Apache POI异常白space(已解决:\u00A0不破space)
Apache POI Anomalous Whitespace (Resolved: \u00A0 non-breaking space)
编辑:已解决的答案:是 00a0 不间断 space,而不是 c0a0 不间断 space。
在使用 Apache POI 将 docx 转换为纯文本,然后将纯文本读入 Java 并尝试对其进行解析后,我 运行 遇到了以下问题。
输出:
" "
first characterequals SPACE OR TAB
false
[B@5e481248
[B@66d3c617
ARRAYTOSTRING SPACE: [32]
ARRAYTOSTRING ?????: [-62, -96]
代码:
System.out.println("\t\"" + line.substring(0,1) + "\"\n\tfirst characterequals SPACE OR TAB \n\t" + (line.substring(0,1).equals(" ")
|| line.substring(0,1).equals("\t") ));
System.out.println(line.substring(0,1).getBytes());
System.out.println(" ".getBytes());
System.out.println("ARRAYTOSTRING SPACE: " + Arrays.toString(" ".getBytes()));
System.out.println("ARRAYTOSTRING ?????: " + Arrays.toString(line.substring(0,1).getBytes()));
String.trim()不去掉
String.replaceAll("\s" , "") 没有去掉它
我正在尝试解析一个巨大的材料文档,这变成了一个主要障碍。我不知道发生了什么或如何与之交互,任何人都可以阐明这里发生的事情吗?
这转换为具有十六进制代码 c2 a0
的字节,根据 this answer 是 UTF-8 编码的不间断 space。请注意,这 不是 真正的 space 并且 \s 不会匹配它。
这对我有用:
String valor = org.apache.commons.lang3.StringUtils.normalizeSpace(java.text.Normalizer.normalize(valor, java.text.Normalizer.Form.NFD));
编辑:已解决的答案:是 00a0 不间断 space,而不是 c0a0 不间断 space。
在使用 Apache POI 将 docx 转换为纯文本,然后将纯文本读入 Java 并尝试对其进行解析后,我 运行 遇到了以下问题。
输出:
" "
first characterequals SPACE OR TAB
false
[B@5e481248
[B@66d3c617
ARRAYTOSTRING SPACE: [32]
ARRAYTOSTRING ?????: [-62, -96]
代码:
System.out.println("\t\"" + line.substring(0,1) + "\"\n\tfirst characterequals SPACE OR TAB \n\t" + (line.substring(0,1).equals(" ")
|| line.substring(0,1).equals("\t") ));
System.out.println(line.substring(0,1).getBytes());
System.out.println(" ".getBytes());
System.out.println("ARRAYTOSTRING SPACE: " + Arrays.toString(" ".getBytes()));
System.out.println("ARRAYTOSTRING ?????: " + Arrays.toString(line.substring(0,1).getBytes()));
String.trim()不去掉
String.replaceAll("\s" , "") 没有去掉它
我正在尝试解析一个巨大的材料文档,这变成了一个主要障碍。我不知道发生了什么或如何与之交互,任何人都可以阐明这里发生的事情吗?
这转换为具有十六进制代码 c2 a0
的字节,根据 this answer 是 UTF-8 编码的不间断 space。请注意,这 不是 真正的 space 并且 \s 不会匹配它。
这对我有用:
String valor = org.apache.commons.lang3.StringUtils.normalizeSpace(java.text.Normalizer.normalize(valor, java.text.Normalizer.Form.NFD));