gpt4 book ai didi

cocoa - NSString 和 UTF8 十六进制转换

转载 作者:行者123 更新时间:2023-12-03 18:04:18 24 4
gpt4 key购买 nike

在此函数中,我从连接到名为 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com