我正在尝试使用一些给定的示例在两个字符串之间查找文本,在特定情况下,我能够做到这一点,但是当涉及到十六进制(使用相同的标识符)时,我遇到了错误。 请指导我在...之间获取价值。...下面给出的示例和错误... 注意-我有大文本(大约9999个完整的文本文件),我只提供了正常工作的示例文本
private static void modifyText() {
String str1 = "private final byte[] record1 = new byte[]{sdfjsdkhfkjsdf hgb sdjfkhsdkfsdf |sdfjksdhfjksd sdf sdkjfhsdkf | sdkjfh hgb sdkjfdshfks|}";
String result1 = str1.substring(str1.indexOf("byte[] record1 = new byte[]{") , str1.indexOf("}"));
System.out.println("\n found1\n"+result1);
String pattern1 = "record1 = new byte[]{";
String pattern2 = "}";
String text= "private final byte[] record1 = new byte[]{\r\n (byte)0x70,(byte)0x80}"; //**for small text it is working**
String result = text.substring(text.indexOf(pattern1) + 1, text.indexOf(pattern2));
System.out.println("\n found2\n"+result);
}
found1在下面完美打印 byte [] record1 = new byte [] {sdfjsdkhfkjsdf hgb sdjfkhsdkfsdf | sdfjksdhfjksd sdf sdkjfhsdkf | sdkjfh hgb sdkjfdshfks |
虽然发现2表示错误------- java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:-799 在java.lang.String.substring(未知来源)