Search code examples
objective-cnsstringcharnsmutablestringunichar

Appending unichar to NSMutableString


How do you append a unichar character to NSMutableString?

unichar c = 'T';
NSMutableString *s = [NSMutableString stringWithString:@"MyString"];

// want s to become "MyStringT"

https://discussions.apple.com/thread/1679290 suggests:

[s appendString:[NSString stringWithCharacters:&c length:1]];

Looks too long / complicated...


Solution

  • Use [NSString appendFormat:], so for above:

    [s appendFormat:@"%C", c];
    

    Enjoy!