gpt4 book ai didi

Java - Objective C char UTF-8 问题

转载 作者:行者123 更新时间:2023-12-02 00:37:45 26 4
gpt4 key购买 nike

我在 Java UTF-8 转换方面遇到了一些问题。我有这个 Objective C 代码:

const char *p = [[NSString stringWithFormat:@"0x%@",md5Hash] UTF8String];

其中md5Hash是NSString,我需要找到一种方法在Java中声明相同的char p,但没有找到如何将char设置为UTF-8。

有什么想法或建议吗?

最佳答案

我不了解 Objective C,但在 Java 中,字符是 UTF-16,而字符串内部字符缓冲区也是如此。如果需要,您可以在 UTF-8 之间进行转换:

// creates a String from the bytes understanding them as UTF-8 chars
byte[] data = ...
new String(data, "UTF-8");

// get the bytes that would represent that string in UTF-8
String myString = "Hello";
myString.getBytes("UTF-8");

希望对你有帮助...

注意:如果您需要流解决方案,您还可以使用 InputStreamReader 和 OutputStreamWriter 进行相同的转换,但那是另一个故事了......

关于Java - Objective C char UTF-8 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7267494/

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