NouNou
NouNou

Reputation: 185

NSString to HEX

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.

Upvotes: 1

Views: 769

Answers (2)

user529758
user529758

Reputation:

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.

Upvotes: 2

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143279

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

Upvotes: 0

Related Questions