如何删除NSString中的撇号和空格

时间:2011-10-29 12:48:39

标签: iphone objective-c nsstring

NSString *str = @"mario's test";
NSString *stringWithoutSpaces = [str stringByReplacingOccurrencesOfString:@" " withString:@""];

使用此功能我可以删除空格,但我还需要删除撇号'

stringWithoutSpaces = "mariostest"

1 个答案:

答案 0 :(得分:5)

*stringWithoutSpaces = [[str stringByReplacingOccurrencesOfString:@" " withString:@""]
                             stringByReplacingOccurrencesOfString:@"'" withString:@""];