NSString *re = [[sqlArray objectAtIndex:0] valueForKey:@"Question"];
question = [re stringByReplacingOccurrencesOfString:@"í" withString:@"'"];
question = [re stringByReplacingOccurrencesOfString:@"î" withString:@"'"];
question = [re stringByReplacingOccurrencesOfString:@"í" withString:@"'"];
question = [re stringByReplacingOccurrencesOfString:@"ì" withString:@"'"];
question = [re stringByReplacingOccurrencesOfString:@"ë" withString:@"'"];
NSLog(@"question : %@",question);
字符串仍然没有被替换,它显示
问题:逗留时间最长的居民√≠
通常是那些
作为nslog。 什么可能是错的?
答案 0 :(得分:3)
试试这个:
NSString *re = [[sqlArray objectAtIndex:0] valueForKey:@"Question"];
question = [re stringByReplacingOccurrencesOfString:@"í" withString:@"'"];
question = [question stringByReplacingOccurrencesOfString:@"î" withString:@"'"];
question = [question stringByReplacingOccurrencesOfString:@"í" withString:@"'"];
question = [question stringByReplacingOccurrencesOfString:@"ì" withString:@"'"];
question = [question stringByReplacingOccurrencesOfString:@"ë" withString:@"'"];
NSLog(@"question : %@",question);
答案 1 :(得分:0)
当您重复设置question = ...
时,您只是更改了局部变量而不是Question
键的值。所以用
[[sqlArray objectAtIndex:0] setObject:question forKey:@"Question"];
(假设这是一个NSDictionary;也许你应该使用setValue:forKey:
,但是如果没有看到更多的代码,我就无法分辨。)
此外,正如joern指出的那样,您应该在第一次替换后使用question = [question stringBy...
而不是question = [re stringBy...
。