简体   繁体   English

Java Split ISO-8859-1 String with "broken vertical bar"

[英]Java Split ISO-8859-1 String with "broken vertical bar"

I read from a third system an ISO-8859-1 coded String.我从第三个系统中读取了 ISO-8859-1 编码字符串。 I have to split this String with the character ¦.我必须将这个字符串与字符 ¦ 分开。 This char has in ISO-8859-1 the value 166. The following code doesn't work, because the value in Java (UTF-8) of ¦ is 65533.这个字符在 ISO-8859-1 中的值为 166。下面的代码不起作用,因为在 Java (UTF-8) 中的值是 65533。

String [] parts = isoString.split("¦");

I am stuck... How can I solve this?我被卡住了......我该如何解决这个问题? Thanks谢谢

Working code:工作代码:

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]

您首先需要将ISO-8859-1 字符串正确解码为 Unicode 表示,以便您可以使用您提供的 Unicode 字符串文字 ( | ) 将其拆分——当然,假设您正在使用 Unicode 编码编译程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM