0

I'm fetching data from a sqlite database in my iOS program. What I get from the DB is then placed in a UITextView. An example of text that is fetched is:

"Hello this is a example. It has "" double quotes "" and ends with simple"

I want to eliminate the single one, and replace the double by singles. But It's not working. Here is my code:

NSString *question;
question = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement1,1)] copy];   
question = [question stringByReplacingOccurrencesOfString:@"\"\"" withString:@"$$"];   
question = [question stringByReplacingOccurrencesOfString:@"\"" withString:@""];   
question = [question stringByReplacingOccurrencesOfString:@"$$" withString:@"\""];

What is wrong?

1 Answer 1

1

The code looks okay; I tried it by doing

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:@"\""];

and it worked fine (well, except for the fact that there are extra spaces next to where the quotes used to be, but it's hard to know what you want there)

If you add some

NSLog(@"question is now: %@", question);

lines you'll probably be able to tell what's going on or if not you'll at least have some more information to post!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.