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:
#import <Foundation/Foundation.h>
@interface NSString (NonStandardPercentEscapes)
- (NSString *) stringByAddingNonStandardPercentEscapes;
@end
And, in a source file (perhaps called NSString+NonStandardPercentEscapes.m
) put the following:
#import "NSString+NonStandardPercentEscapes.h"
@implementation NSString (NonStandardPercentEscapes)
- (NSString *) stringByAddingNonStandardPercentEscapes
{
NSCharacterSet *mustEscape = [NSCharacterSet characterSetWithCharactersInString:@"<>~\"{}|\\-`^% "];
NSMutableString *result = [[NSMutableString alloc] init];
NSUInteger length = [self length];
unichar buffer[length];
[self getCharacters:buffer range:NSMakeRange(0, length)];
for (NSUInteger i = 0; i < length; i++)
{
if ([mustEscape characterIsMember:buffer[i]])
[result appendFormat:@"%%%02hhx", buffer[i]];
else if (buffer[i] > 0xFF)
[result appendFormat:@"%%u%04hx", buffer[i]];
else if (!isascii((int)buffer[i]))
[result appendFormat:@"%%%02hhx", buffer[i]];
else
[result appendFormat:@"%c", buffer[i]];
}
// return the mutable version, nobody will know unless they check the class
return [result autorelease];
// alternatively, you can force the result to be immutable
NSString *immutable = [[result copy] autorelease];
[result release];
return immutable;
}
@end
Then, wherever you need to encode your Hebrew string, you can do the following (as long as your source file includes the above header):
NSString * urlS = @"http://irrelevanttoyourinterests/some.aspx?foo=bar&this=that&Text=תל אביב";
urlS = [urlS stringByAddingNonStandardPercentEscapes];
NSUrl *url1 = [NSURL URLWithString:urlS];
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.