我正在从 iOS 程序中的 sqlite 数据库获取数据。然后我从数据库获得的内容被放置在 UITextView 中。获取的文本示例如下:
“您好,这是一个示例。它有“”双引号“”并以简单结尾”
我想消除单打,用单打代替 double 。但它不起作用。这是我的代码:
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);
您可能能够知道发生了什么,或者如果不能,您至少可以发布更多信息!
关于ios - 替换 Objective-C 中出现的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1147495/