ios - 替换 Objective-C 中出现的字符串

标签 ios objective-c nsstring

我正在从 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/

相关文章:

ios - 将 subview 添加到 UICollectionViewCell 子类?

ios - UITableViewCells 未出现在第二个选项卡中

ios - 向 UIPangesture 添加边界

ios - 再次出示GameCenter验证VC

objective-c - 检查 NSString 是否只包含一个重复字符

来自 UITextField 的 iOS NSString - 检查值

ios - 快速将NSNumber转换为String时出错

ios - 复选标记不会打开/关闭

ios - UIAlertView 不打开 url?

objective-c - NSAlert 显示错位的按钮