我的字符串是“apple”
我想把它当苹果只
如何从我的NSstring中替换那些双引号。
例如:
NSstring *str=[str stringByReplacingOccurrencesOfString:@""" withString:@""];
答案 0 :(得分:6)
NSString *str = @"\"apple\"";
NSLog(@"%@",str);
str = [str stringByReplacingOccurrencesOfString:@"\"" withString:@""];
NSLog(@"after--%@",str);
答案 1 :(得分:2)
转义旧字符串中的双引号字符:
NSString *str2 = [str stringByReplacingOccurrencesOfString:@"\"" withString:@""];
答案 2 :(得分:1)
如果你想让任何特殊字符如“,&,”作为字符串的一部分,那么在该特殊字符之前使用反斜杠()转义字符。
的更多信息NSstring *str=[str stringByReplacingOccurrencesOfString:@"\"" withString:@""];
答案 3 :(得分:1)
尝试使用以下内容:
NSString * myString = [oldString stringByReplacingOccurrencesOfString:@" \"" withString:@""];
答案 4 :(得分:0)
NSString *s = @"\"a\""; // s = "a"
NSString *str=[s stringByReplacingOccurrencesOfString:@"\"" withString:@""];
NSLog(@"s: %@",str); //s: a
答案 5 :(得分:0)
NSString *test = @"\"Apple\"";
NSLog(@"%@", test);
NSCharacterSet *doNotWantTheseCharacters = [NSCharacterSet characterSetWithCharactersInString:@"\""];
test = [[test componentsSeparatedByCharactersInSet: doNotWantTheseCharacters] componentsJoinedByString: @""];
NSLog(@"%@", test);
以上代码可用于替换字符串中的字符。