例として挙げたパーセント エスケープは Unicode コード ポイントです。このタイプのエンコーディングは非標準であるため、これを行う方法が既に存在する可能性は低いと思います。自分で巻く必要があるかもしれませんが、それほど難しくありません。
ヘッダー (おそらく と呼ばれるNSString+NonStandardPercentEscapes.h) に次のように記述します。
#import <Foundation/Foundation.h>
@interface NSString (NonStandardPercentEscapes)
- (NSString *) stringByAddingNonStandardPercentEscapes;
@end
そして、ソース ファイル (おそらく と呼ばれるNSString+NonStandardPercentEscapes.m) に次のように記述します。
#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
次に、ヘブライ文字列をエンコードする必要がある場合は、次の操作を実行できます (ソース ファイルに上記のヘッダーが含まれている場合)。
NSString * urlS = @"http://irrelevanttoyourinterests/some.aspx?foo=bar&this=that&Text=תל אביב";
urlS = [urlS stringByAddingNonStandardPercentEscapes];
NSUrl *url1 = [NSURL URLWithString:urlS];
免責事項:
どの文字をエスケープする必要があり、どの時点でエスケープを開始する必要があるのか わかりません(これはおそらくあなたが望むものではないURL全体をエンコードするだけです)が、上記のコードは少なくともあなたを始めるはずです.