I’m learning Objective C and iOS development. I’m trying to recreate some of the projects we did in my Java class (I know they’re completely different) but I’m running into trouble in one of the projects. We were doing a caesar shift in a lab one day. A string manipulation lab. It was a really basic deal in Java… a for loop through the string and change each character. I can’t seem to find any way to change individual characters in Objective C. I’ve looked through the NSMutableString documentation and NSString documentation and I know I can do a
[NSString stringByReplacingCharactersInRange:(NSRange *) withString:(NSString *)
but that doesn’t really help because I don’t know what I’m going to be replacing with. I need to find a way to grab a character at a specific index and change it. Any ideas?
Sounds like you are looking for the
[NSString characterAtIndex:(NSUInteger)]methodE.g.
Result: a
Using this, and an
NSMutableString, you can build the string you need.Ussing
appendStringyou can add to the end of anNSMutableString