cocoa - NSString 和 UTF8 十六进制转换

标签 cocoa utf-8 nsstring nsarray

在此函数中,我从连接到名为 emotes 的 IBOutlet 的 NSArrayController 中的 NSTableView 获取选定的表情符号。所选 NSArray 中的字符串包含发送到剪贴板的 UTF8 字符。

// Get Selected Emoticon
NSArray * selectedemote = [emotes selectedObjects];
NSLog(@"%@",[selectedemote valueForKey:@"emote"]);
// Send to Clipboard
[self copyToClipboard:[NSString stringWithFormat:@"%@",[selectedemote valueForKey:@"emote"]]];

问题出在 NSArray 本身。它似乎将 UTF8 字符串输出为十六进制。 NSLog 函数中的字符串如下所示:

2010-08-23 11:23:56.411 Emoticon[7919:a0f] (
    "\\(\U2579\U30ee\U2579 )/"
)

是否有可能将 UTF-8 十六进制转换为 UTF-8 字符?谢谢。

最佳答案

我解决了这个问题。解决方案是使用 NSEntityDescription 并使用选定单元格的 NSArray 中的 objectAtIndex:0 对其进行初始化。使用 NSEntityDescription,我获得了 Emote 的值。

-(IBAction)sendtoclipboard:(id)sender
{
    // Get Selected Emoticon
    NSArray * selectedemote = [emotes selectedObjects];
    NSEntityDescription *entity = [selectedemote objectAtIndex:0];
    NSString * tmpemote = [NSString stringWithFormat:@"%@",[entity valueForKey:@"emote"]];
    NSLog(@"%@", [entity valueForKey:@"emote"]);
    //Send to Clipboard
    [self copyToClipboard:tmpemote];
}

结果:

2010-09-07 20:03:26.488 Emoticon[45764:a0f] \(╹ヮ╹ )/

关于cocoa - NSString 和 UTF8 十六进制转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3549167/

相关文章:

perl - 如何通过 Email::Simple 发送电子邮件?

objective-c - QInputDialog 类似于 Cocoa/Xcode 中的东西?

unicode - 检查 Unicode 字符串中的空格 - 逐字节检查!

python - 将 Bytearray 编码为 UTF-8

iphone - 将 NSDate 转换为 NSString

iOS - 使用空格解析字符串

xcode - 非事件窗口上带有自定义图像的 Mac 圆形纹理按钮

cocoa - NSView EnterFullScreenWithOptions : scaling the NSView

objective-c - 在测试中转换 NSRange 吗?

ios - 自定义格式化文本标签的字符串值