[英]How to delete NSString's text from another NSString
For example: 例如:
NSString *sentence = @"My name is Roman";
NSString *name = @"Roman";
Is there way to delete name
's text from sentence
string? 有没有办法从sentence
字符串中删除name
的文本?
NSString* result = [sentence stringByReplacingOccurrencesOfString:name withString:@""];
是
sentence = [sentence stringByReplacingOccurrencesOfString:name withString:@""];
Alternatively, you can use substringWithRange:
like so: 另外,您可以使用substringWithRange:
所示:
NSString *finalString = [sentence substringWithRange:NSMakeRange(3, 16)]; NSString * finalString = [句子substringWithRange:NSMakeRange(3,16)];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.