[英]Replacing occurrences of strings in Objective-C
我正在从iOS程序的sqlite数据库中获取数据。 然后,我从数据库中获得的内容将放在UITextView
。 提取的文本示例为:
“您好,这是一个例子。它带有“”双引号“”,并以简单结尾”
我要消除单身,并用单身代替双身。 但这不起作用。 这是我的代码:
NSString *question;
question = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement1,1)] copy];
question = [question stringByReplacingOccurrencesOfString:@"\"\"" withString:@"$$"];
question = [question stringByReplacingOccurrencesOfString:@"\"" withString:@""];
question = [question stringByReplacingOccurrencesOfString:@"$$" withString:@"\""];
怎么了?
代码看起来还不错; 我尝试过
NSString *question = @"\"Hello this is a example. It has \"\" double quotes \"\" and ends with simple\"";
question = [question stringByReplacingOccurrencesOfString:@"\"\"" withString:@"$$"];
question = [question stringByReplacingOccurrencesOfString:@"\"" withString:@""];
question = [question stringByReplacingOccurrencesOfString:@"$$" withString:@"\""];
并且效果很好(嗯,除了以前引号旁边还有多余的空格,但这很难知道您想要的地方)
如果添加一些
NSLog(@"question is now: %@", question);
行中,您可能可以分辨出发生了什么,否则,至少需要发布更多信息!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.