我在旧的 VB6 类中有以下内容,我需要将其移动到 Android 中的 Java 类。
tmp = StrConv(vValue, vbUnicode, AESLOCALE)
tmp = StrConv(vData, vbFromUnicode, AESLOCALE)
其中 AESLOCALE 是 1033
我四处寻找,但似乎不知道如何解决这个问题。 谢谢
最佳答案
看起来您只需要在英语(Locale 1033 或 ISO_8859_1)和 unicode (UTF_16) 之间来回转换即可。
首先,确保导入字符集:
import static java.nio.charset.StandardCharsets.*;
对于问题中的第一行,您可以使用它以 UTF-16 编码字符集:
//Convert to unicode/UTF_16:
byte[] engilshBytes = myString.getBytes(ISO_8859_1);
String unicodeValue = new String(engilshBytes, UTF_16);
对于问题的底线,您可以使用它在 ISO_8859_1 中对 unicode 进行编码:
//Convert to english/ISO_8859_1:
byte[] unicodeBytes = myString.getBytes(UTF_16);
String englishValue = new String(unicodeBytes, ISO_8859_1);
编辑:
关于字符集的 Android 页面链接(自 Android 4.4 起可用):
https://developer.android.com/reference/java/nio/charset/StandardCharsets
链接到有关字符集的 Java 页面(NIO 从 Java 7 开始工作):
https://docs.oracle.com/javase/8/docs/api/java/nio/charset/Charset.html
关于java - 是否有相当于 VB6 Strconv 的 Java(Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52268650/