简体   繁体   中英

How does NSString/NSMutableString terminate?

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 that 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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM