【问题标题】:Showing unicode in the console in the right format在控制台中以正确的格式显示 unicode
【发布时间】:2013-04-10 05:06:07
【问题描述】:
NSSet *subFolders = [_account subscribedFolders];
NSLog(@"subFolders: %@",subFolders);

输出:

...
    "[Gmail]/\U05d8\U05d9\U05d5\U05d8\U05d5\U05ea",
    "[Gmail]/\U05d7\U05e9\U05d5\U05d1" 
...

有什么方法可以用原始语言(希伯来语)显示上述文本?

我尝试过的事情:

  • 将调试器从 LLDB 更改为 GDB - 无效
  • 在首选项下检查 -> 文本编辑 UTF-* 被选中

谢谢

【问题讨论】:

  • 也许这会有所帮助:stackoverflow.com/questions/3372103/…
  • 试过了,我无法对 NSSet 进行编码,我猜它对 NSString 有效,但事实并非如此。
  • 你可以试试 NSString *desc = [yourNSSet description];
  • 试图做这样的事情NSString *desc = [subFolders description]; NSString *demo=[[NSString alloc] initWithData: [NSData dataWithBytes:(__bridge const void *)(desc) length:[desc length]] encoding:NSUnicodeStringEncoding]; NSLog(@"%@",demo); 它甚至不会打印单词演示。我收到了在 initWithData 中使用办公桌的警告,所以我尝试使用 __bridge 但这没有帮助

标签: ios objective-c xcode cocoa-touch cocoa


【解决方案1】:

在控制台中显示 unicode 字符没有问题,所以我认为这是字符串首先进入集合的方式。

我建议使用以下内容遍历 subFolders 中的所有对象:

 for( id object in [subFolders allObjects] ) {
    //Print out the name of the item explicitly
 }

即使这不起作用,它至少可以让您直接使用字符串。如果还在打印:

“[Gmail]/\U05d8\U05d9\U05d5\U05d8\U05d5\U05ea”

看起来好像您正在收到转义的 unicode 字符,我建议这样做:https://stackoverflow.com/a/7861345/352891 - 这可能直接适用于 NSSet 的描述

【讨论】:

  • 您使用 NSSet 描述的第二个解决方案效果很好。谢谢
【解决方案2】:
 NSString* strOld=[NSString stringWithFormat:@"%@",responseObject];
NSLog(@"%@",[NSString
             stringWithCString:[strOld cStringUsingEncoding:NSUTF8StringEncoding]
             encoding:NSNonLossyASCIIStringEncoding]);

【讨论】:

  • 你能解释一下为什么这对 OP 有帮助吗?
  • 完美答案。像魅力一样工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-15
  • 1970-01-01
  • 2015-11-01
  • 2021-09-27
  • 2021-02-13
  • 1970-01-01
相关资源
最近更新 更多