The title pretty much sums it up. I have a hebrew-containing String used in a NSUrl:
NSString * urlS = @"http://irrelevanttoyourinterests/some.aspx?foo=bar&this=that&Text=תל אביב"
I would like to convert in into:
Text=%u05EA%u05DC%20%u05D0%u05d1%u05d9%u05d1
and then send it as a GET request.
I have tried many encoding methods unsuccessfully, and eventually I tried statically inserting the encoded string into the URL, quoted above.
NSURL *url1 = [NSURL URLWithString:urlS];
Then I use startAsyncLoad which you may be familiar with (here), but when the URL is constracted with the static Unicode string, nothing gets sent (checked with Wireshark), although if I use the following line before the startAsyncLoad it sends (wrongly encoded, of course).
urlS = [urlS stringByAddingPercentEscapesUsingEncoding:NSWindowsCP1254StringEncoding];
Thanks in advance.
The percent escapes that you have given as an example are Unicode code points. This type of encoding is non-standard, so I think it is unlikely that there exists a method already that can do this. You may have to roll your own, but it’s not too difficult.
In a header (perhaps called
NSString+NonStandardPercentEscapes.h) put the following:And, in a source file (perhaps called
NSString+NonStandardPercentEscapes.m) put the following:Then, wherever you need to encode your Hebrew string, you can do the following (as long as your source file includes the above header):
Disclaimer:
I have no idea what characters need to be escaped and at what point the escaping should start (this just encodes the entire URL which is probably not what you want), but the above code should at least get you under way.