tags:

views:

154

answers:

1

Hello,

I'm fetching data from a sqlite database in my iPhone 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?

Thanks very much!

+1  A: 

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!

David Maymudes