开发者

iphone : problem replacing string

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜