1

example: NSString *day = [[NSString stringWithFormat:@"السبت"];and i think the

representation of this string in hex is this :%C7%E1%D3%C8%CA (windows-1256 encoding)

what i want is how to convert arabic string to hex like this.

NouNou
  • 185
  • 4
  • 12

2 Answers2

2

A possible solution:

NSString *day =@"السبت";
NSData *strData = [day dataUsingEncoding:NSWindowsCP1254StringEncoding];
NSMutableString *mut = [NSMutableString string];
int i;
for (i = 0; i < [strData length]; i++)
{
    [mut appendFormat:@"%%%02X", ((char *)[strData bytes])[i]];
}

mut will contain the hexadecimal encoded representation of day.

  • 1
    maybe... we don't have enough info to know how 00-0f should be formatted, if they should be zero padded or not, if so the format should be @"%%%0.2X" – Grady Player Jan 13 '12 at 20:56
0

Something like [day stringByAddingPercentEscapesUsingEncoding:@"whatever"] ?

Michael Krelin - hacker
  • 138,757
  • 24
  • 193
  • 173
  • it won't properly escape characters... An other way is to use the CoreFoundation functions, but that's somewhat more complicated. My solution will escape all Arabic characters. –  Jan 13 '12 at 20:46