stringByAddingPercentEscapesUsingEncoding not working with NSStrings with ' 0'

前端 未结 2 2075
广开言路
广开言路 2020-12-17 05:21

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

When I try to use the method to conver

相关标签:
2条回答
  • 2020-12-17 05:29

    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 讨论(0)
  • 2020-12-17 05:53

    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.

    0 讨论(0)
提交回复
热议问题