0

例如:

NSString *sentence = @"My name is Roman";
NSString *name  = @"Roman";

有没有办法从字符串中删除name的文本?sentence

4

3 回答 3

10
NSString* result = [sentence stringByReplacingOccurrencesOfString:name withString:@""];
于 2012-07-06T17:10:03.467 回答
8

是的

sentence = [sentence stringByReplacingOccurrencesOfString:name withString:@""];
于 2012-07-06T17:11:01.180 回答
1

或者,您可以substringWithRange:像这样使用:

NSString *finalString = [句子 substringWithRange:NSMakeRange(3, 16)];

于 2012-07-06T17:33:16.537 回答