如何将 ş 编码为可读字符串?

How to encode ȭ into readable string?

我正在从 URL 获取文本数据,但有一个特定字符似乎没有正确编码 -> Ş

我知道那个字符是什么,所以我尝试手动将其编码为 utf-8,但 xcode 甚至无法识别该字符

NSLog(@"before: %@", brokenCharacter);
if([brokenCharacter isEqualToString: @"ȭ"]) brokenCharacter = @"A";
NSLog(@"after: %@", brokenCharacter);

我得到的 NSLog 是:

before: ȭ
after: ȭ

这个问题有解决办法吗?

可以使用NSUTF16BigEndianStringEncoding作为编码参数

NSString *brokenCharacter = @"ȭ";
NSLog(@"before: %@", brokenCharacter);
NSData *dataCharacter = [brokenCharacter dataUsingEncoding:NSUTF16BigEndianStringEncoding];
brokenCharacter = [NSString stringWithUTF8String:[dataCharacter bytes]];
NSLog(@"after: %@", brokenCharacter);