In Objective C, I have a NSMutableString
and I am accessing its characters using characterAtIndex:
method for some manipulation.
For this, I also have to check for the terminating character somewhat like this:
NSMutableString *str = [[NSMutableString alloc]initWithString:@"hello"];
for(int i = 0; [str characterAtIndex:i] != '???'; i++) // ??? = terminator
//do something
So, as the above code defines, I am confused about the terminating character that NSString/NSMutableString uses. Is it \0
like in char *
or something else?
Any help on this is appreciated.
There is no terminator. You use the length
method.
for (NSUInteger i = 0; i < str.length; i++) {
unichar ch = [str characterAtIndex:i];
// do stuff
}