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