我在我的iPhone程序中从sqlite数据库中获取数据。然后我从DB获得的内容放在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:@"\""];
有什么问题?
非常感谢!
答案 0 :(得分:1)
代码看起来不错;我试着做了
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);
你可能会知道发生了什么,或者如果没有,你至少会有更多的信息要发布!