例如:
NSString *sentence = @"My name is Roman";
NSString *name = @"Roman";
有没有办法从name
字符串中删除sentence
的文字?
答案 0 :(得分:10)
NSString* result = [sentence stringByReplacingOccurrencesOfString:name withString:@""];
答案 1 :(得分:8)
是
sentence = [sentence stringByReplacingOccurrencesOfString:name withString:@""];
答案 2 :(得分:1)
或者,您可以像这样使用substringWithRange:
:
NSString * finalString = [sentence substringWithRange:NSMakeRange(3,16)];