I need to get url string from NSString. I do the following:
NSString * str = [NSString stringWithString:@"i@gmail.com"];
NSString * eStr = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@",eStr);
The result is i@gmail.com. But I need i%40gmail.com. replacing NSUTF8StringEncoding with NSASCIIStringEncoding doesn’t help.
You’re using the wrong method. This does the opposite, translating percent
escapes to their characters. You probably want to use
stringByAddingPercentEscapesUsingEncoding:.Apart from that, looks like the
@character is not escaped by default. Then,as the documentation for the above method points out, you’ll need to use
CoreFoundation to achieve what you want.
Please check the documentation to know more about the function used and
how to make it fit your needs.