简体   繁体   English

如何从另一个NSString删除NSString的文本

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM