我有一长串一些字符。我想用其他字符替换一些字符。
例如
string1="Hello WORLD12";
string2="world";
string1= search string2 in string1 and replace it;
//need this method in objective c
string1="Hello world12";
最佳答案
如果不区分大小写是指小写替换,Ken Pespisa 有答案,但如果不区分大小写是关于您的搜索字符串,您可以这样做:
[mystring stringByReplacingOccurrencesOfString:@"searchString" withString:@"replaceString" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [mystring length])];
有关更多信息,请参阅文档:
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement options:(NSStringCompareOptions)options range:(NSRange)searchRange;
关于ios - 如何在 objective-c iphone 中替换不区分大小写的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6236581/