java - 测试十六进制值

标签 java

我想捕获这个异常,并且我想在 catch block 中进行一些处理,这是代码:

  try {
root.setText(page.getText(field.getLine() + repetition,
                          field.getColumn(),
                          field.getLength()));
  } catch (org.jdom2.IllegalDataException e) {
// ignore: some lines can be empty and cannot
// be a valid XML character so we skip them

String invalidStr = page.getText(field.getLine() + repetition, field.getColumn(),field.getLength());

  }

这是我使用 e.printStackTrace() 时打印的错误;方法:

org.jdom2.IllegalDataException: The data "
                                      " is not legal for a JDOM character content: 0x000c is not a legal XML character.
at org.jdom2.Text.setText(Text.java:182)

那么如何测试字符0x000c的值:

    String invalidStr = page.getText(field.getLine() + repetition, field.getColumn(),field.getLength());
    if (invalidStr.equals(???)) {
    }

提前谢谢

最佳答案

if (invalidStr.indexOf(0x000C) >= 0) ...

或者

if (invalidStr.indexOf('\u000C') >= 0) ...

或者

if (invalidStr.contains("\u000C")) ...

(使用Unicode escape)

关于java - 测试十六进制值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23789112/

相关文章:

java - 为什么编译器会对待 List<?> 和 List<?以不同方式扩展 Object>?

java - 无法获得两个日期时间之间的差异?

java - 为什么这个简单的 java fork 加入池不起作用?

java - 在wiremock中使用ResponseTransformer总是得到空响应

java.lang.RuntimeException : Unable to start activity ComponentInfo java. lang.NullPointerException

java - 为什么在使用 DiskFileItem 时出现不确定性文件删除错误?

java - 当我尝试在 Spring Controller 的方法中将 json 字符串映射到 java 域类时出现 MethodArgumentConversionNotSupportedException

java - 在java中从套接字获取输入和输出流的问题

java - 以编程方式向 xml 添加注释

java - 你如何在 Java 中使用 Ruby?