我想用字符串中的单引号替换所有双引号。我尝试过使用stringByReplacingOccurrencesOfString
,但它不起作用。如何使用单引号替换所有双引号,以便将其存储到数据库中?
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);
}
答案 0 :(得分:1)
string=[string stringByReplacingOccurrencesOfString:@"\"" withString:@"'"];