开发者

Insert a characters in NSString

开发者 https://www.devze.com 2022-12-13 04:23 出处:网络
I am having difficulty with subj. I have NSString text, contains \"SLOVO\", and i need that NSMutableString* currentRequest contain \"%t%e%x%t%\".

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号