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开发者_JAVA百科 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.
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:
- String Format Specifiers
- NSString characterAtIndex method
精彩评论