[ACCEPTED]-Replacing one character in a string in Objective-C-nsstring
Accepted answer
If it is always the same character you can 4 use:
stringByReplacingOccurrencesOfString:withString:
If it is the same string in the same 3 location you can use:
stringByReplacingOccurrencesOfString:withString:options:range:
If is just a specific 2 location you can use:
stringByReplacingCharactersInRange:withString:
Documentation here: https://developer.apple.com/documentation/foundation/nsstring
So 1 for example:
NSString *someText = @"Goat";
NSRange range = NSMakeRange(0,1);
NSString *newText = [someText stringByReplacingCharactersInRange:range withString:@"B"];
newText would equal "Boat"
NSString *str = @"123*abc";
str = [str stringByReplacingOccurrencesOfString:@"*" withString:@""];
//str now 123abc
0
Here is the code:
[aString stringByReplacingCharactersInRange:NSMakeRange(3,1) withString:@"B"];
0
Use the replaceCharactersInRange: withString:
message on a NSMutableString
object.
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.