Java 用 "broken vertical bar" 拆分 ISO-8859-1 字符串
Java Split ISO-8859-1 String with "broken vertical bar"
我从第三个系统读取了一个 ISO-8859-1 编码的字符串。我必须用字符 ¦ 拆分这个字符串。此字符在 ISO-8859-1 中的值为 166。
以下代码不起作用,因为¦ 的 Java (UTF-8) 中的值为 65533.
String [] parts = isoString.split("¦");
我卡住了...我该如何解决?
谢谢
工作代码:
String s = new String(new byte[] {'a', 'b', (byte) 166, 'c', 'd'},
StandardCharsets.ISO_8859_1);
String[] split = s.split("\u00a6");
System.out.println("split = " + Arrays.toString(split));
// prints split = [ab, cd]
您首先需要 properly decode your ISO-8859-1 string into a Unicode representation 以便您可以使用您提供的 Unicode 字符串文字 (|
) 拆分它 - 当然假设您正在使用 Unicode 编码编译您的程序。
我从第三个系统读取了一个 ISO-8859-1 编码的字符串。我必须用字符 ¦ 拆分这个字符串。此字符在 ISO-8859-1 中的值为 166。 以下代码不起作用,因为¦ 的 Java (UTF-8) 中的值为 65533.
String [] parts = isoString.split("¦");
我卡住了...我该如何解决? 谢谢
工作代码:
String s = new String(new byte[] {'a', 'b', (byte) 166, 'c', 'd'},
StandardCharsets.ISO_8859_1);
String[] split = s.split("\u00a6");
System.out.println("split = " + Arrays.toString(split));
// prints split = [ab, cd]
您首先需要 properly decode your ISO-8859-1 string into a Unicode representation 以便您可以使用您提供的 Unicode 字符串文字 (|
) 拆分它 - 当然假设您正在使用 Unicode 编码编译您的程序。