1

I would like to replace all double quotes with single quotes in a string. I have tried using stringByReplacingOccurrencesOfString but it does not work. How do i make it replace all the double quotes with single quotes so that i can store it into the database?

sqlite3_stmt    *statement;

NSString *string = [NSString stringWithString:charDesc.text];
[string stringByReplacingOccurrencesOfString:@"\"" withString:@"''"];

if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK){
    NSString *insertSQL = [NSString stringWithFormat: @"UPDATE CHARACTER SET charName = \"%@\", charDescription = \"%@\" WHERE charID = %i", charName.text, charDesc.text, charID];

    const char *insert_stmt = [insertSQL UTF8String];

    sqlite3_prepare_v2(database, insert_stmt, -1, &statement, NULL);
    if (sqlite3_step(statement) == SQLITE_DONE){
        status.text = @"Succesfully Updated!";
    }else{
        status.text = @"Failed to Update!";
    }

    sqlite3_finalize(statement);
    sqlite3_close(database); 
}
Asciiom
  • 9,867
  • 7
  • 38
  • 57
icee
  • 39
  • 1
  • 9

1 Answers1

1
string=[string stringByReplacingOccurrencesOfString:@"\"" withString:@"'"];
Mil0R3
  • 3,876
  • 4
  • 33
  • 61