0

我正在从我的 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:@"\""];

怎么了?

4

1 回答 1

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);

行,您可能会知道发生了什么,或者如果不是,您至少可以发布更多信息!

于 2009-07-18T13:43:39.097 回答