开发者

stringByAddingPercentEscapesUsingEncoding not working with NSStrings with ' 0'

I have been having some problem with the stringByAddingPercentEscapesUsingEncoding: method. Here's what happens:

When I try to use the method to conver开发者_运维知识库t the NSString:

"..City=Cl&PostalCode=Rh6 0Nt"

I get this this..

"City=Cl&PostalCode=Rh62t"

It should be:

"..City=Cl&PostalCode=Rh6%200Nt"

What can I do about this? Thanks in advance !!


For me, this:

NSString *s=[@"..City=Cl&PostalCode=Rh6 0Nt" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"s=%@",s);

... outputs:

s=..City=Cl&PostalCode=Rh6%200Nt

You're most likely using the wrong encoding.


This happens when you're trying to encode to NSASCIIStringEncoding a string with characters not supported by ASCII.

Make sure you're encoding to NSUTF8StringEncoding, if the string can contain UTF8 characters or the method would return nil.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜