I'm retrieving a string from url content, this way:
NSString *urlStr = [NSString stringWithFormat:@"http://www.example.com/string_to_retrieve"];
NSURL *url = [NSURL URLWithString:urlStr];
NSString *resp = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:nil];
and writing it to file, this way:
NSString *outFile = @"/path/to/myfile";
[resp writeToFile:outFile atomically:YES encoding:NSUTF8StringEncoding error:nil];
my string contains several special chars like "ö" which should be represented by "F6" hex value, but when i try to open with a hex editor the file where my string is written, i see that "ö" (F6) got converted to two other chars: "ö" (C3 B6)
I tried with several other string encodings in both
NSString *resp = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:nil];
and
[resp writeToFile:outFile atomically:YES encoding:NSUTF8StringEncoding error:nil];
but always with bad results...
NSASCIIStringEncoding
seems to be the only way that i can get that string from my url: if i use other encodings like NSUTF8StringEncoding
all i get is nil
NSUTF8StringEncoding
seems to be the only way i can write to my file: if i use other encodings like NSASCIIStringEncoding
all i get is a 0 byte file
So how can i properly retrieve and write that string to my file?