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);
string i开发者_运维知识库s still not being replaced, it shows
question : Residentí
s with the longest length of stay are generally those who
as nslog. what could be wrong?
Try this:
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);
When you repeatedly set question = ...
, you're just changing a local variable and not the value of the Question
key. So finish this off with
[[sqlArray objectAtIndex:0] setObject:question forKey:@"Question"];
(That's assuming this is an NSDictionary; perhaps you should use setValue:forKey:
otherwise, but I can't tell without seeing more of your code.)
Also, as joern points out, you should use question = [question stringBy...
instead of question = [re stringBy...
after the first replacement.
精彩评论