Sergey Kopanev
Sergey Kopanev

Reputation: 1504

Insert a characters in NSString

I am having difficulty with subj.

I have NSString text, contains "SLOVO", and i need that NSMutableString* currentRequest contain "%t%e%x%t%". I trying in cycle:

     [currentRequest appendFormat:@"%c%%", [text characterAtIndex:i]];

It's working fine, BUT if text contain for example "Rüdiger", i mean non latin symbols, then currentRequest contains full trash !

I've see decide is use (void)insertString:(NSString *)aString atIndex:(NSUInteger)anIndex but i think it is no right way. May be know right way ?

thanks.

Upvotes: 0

Views: 2020

Answers (1)

martin clayton
martin clayton

Reputation: 78215

I may have misunderstood, but I think the issue with appendFormat is a mismatch between the %c format specifier and the return type of the characterAtIndex method.

Method characterAtIndex returns a unichar, whereas %c expects an 8-bit unsigned char. Use %C (uppercase C) instead in your format string.

Some Apple developer docs for reference:

Upvotes: 3

Related Questions