Reputation: 53
I am using this following code snippet to encode the string, which i need to send to REST Api's
NSString* content=@"Test &a=b";
NSString* encodedString=[content stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSLog(@"encodedString :%@",encodedString);
And got the following output
**Test%20&a=b**
Why "&" and "=" characters are not encoded?
But this issue is solved by using "CFURLCreateStringByAddingPercentEscapes" method
Any help please?
Upvotes: 1
Views: 95
Reputation: 3579
Looks like NSASCIIStringEncoding
will convert to 7-bit Ascii, which +
is 43 and &
is 38. Since they are valid 7-bit ASCII chars, I would not expect them to be converted with what you have. Source -
While CFURLCreateStringByAddingPercentEscapes will
replacing certain characters with the equivalent percent escape sequence based on the specified encoding
Sources:
https://en.wikipedia.org/wiki/ASCII
Upvotes: 1