I have a long string of some characters. I want to replace some chars with other chars.
For example
string1="Hello WORLD12";
string2="world";
string1= search string2 in string1 and replace it;
//need this method in objective c
string1="Hello world12";
If by case insensitive you mean the lower case replacement, Ken Pespisa has your answer, but if case insensitivity is about your search string you can do this:
[mystring stringByReplacingOccurrencesOfString:@"searchString" withString:@"replaceString" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [mystring length])];
for more info see documentation of:
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement options:(NSStringCompareOptions)options range:(NSRange)searchRange;
NSString *myString = @"select name SELECT college Select row";
[myString stringByReplacingOccurrencesOfString:@"select" withString:@"update" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [myString length])];
output: @"update name update college update row";
You can call the NSString method stringByReplacingOccurrencesOfString:withString:
NSString *string1 = "Hello WORLD12";
NSString *string2 = "world";
NSString *string3 = [string1 stringByReplacingOccurrencesOfString:@"WORLD" withString:string2];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With