-4

我正在通过 jSoup 解析 HTML 并获得以下输出。文本被注释器分割成段,并用 ||| 标记每个部分。所以,我需要检索每个段。 在此处输入图像描述

File input = new File("C:\\Test\\aaa.html");
                Document doc = Jsoup.parse(input, "UTF-8", "");
                Element body = doc.body();
                String body2 = body.toString();
                String[] test = body2.split("|||");
                for (String s:test)
                System.out.print(s+"111111111");

output: 11111111 111111111<111111111b111111111r111111111>111111111|111111111|111111111|111111111<111111111s111111111t111111111r111111111o111111111n111111111g111111111>111111111 111111111B111111111u111111111s111111111i111111111n111111111e111111111s111111111s111111111 111111111T111111111r111111111a111111111n111111111s111111111f111111111e111111111r111111111s111111111 111111111:111111111 111111111<111111111/111111111s111111111t111111111r111111111o111111111n111111111g111111111>111111111 111111111A111111111s111111111 111111111w111111111e111111111 111111111c111111111o111111111n111111111t111111111i111111111n111111111u111111111e111111111 111111111t111111111o111111111 111111111d111111111e111111111v111111111e111111111l111111111o111111111p111111111 111111111o111111111u111111111r111111111 111111111b111111111u111111111s111111111i111111111n111111111e111111111s111111111s111111111,111111111 111111111w111111111e111111111 111111111m111111111i111111111g111111111h111111111t111111111 111111111s111111111e111111111l111111111l111111111 111111111o111111111r111111111 111111111b111111111u111111111y111111111 111111111a111111111d111111111d111111111i111111111t111111111i111111111o111111111n111111111a111111111l111111111111111111 111111111w111111111e111111111 111111111m111111111i111111111g111111111h111111111t111111111 111111111s111111111e111111111l111111111l111111111 111111111o111111111r111111111 111111111b111111111u111111111y111111111 111111111a111111111d111111111d111111111i111111111t111111111i111111111o111111111n111111111a111111111l111111111111111111 111111111w111111111e111111111 111111111m111111111i111111111g111111111h111111111t111111111 111111111s111111111e111111111l111111111l111111111 111111111o111111111r111111111 111111111b111111111u111111111y111111111 111111111a111111111d111111111d111111111i111111111t111111111i111111111o111111111n111111111a111111111l111111111

4

2 回答 2

0

我只是在猜测,但我认为您正在寻找这样的东西:

String s = "cheese|||bread";
String[] splits = s.split("\\|\\|\\|");
for (String split : splits) {
    System.out.println(split);
}

输出:

cheese
bread

在您的代码中实现:

File input = new File("C:\\Test\\aaa.html");
Document doc = Jsoup.parse(input, "UTF-8", "");
Element body = doc.body();
String body2 = body.toString();
String[] test = body2.split("\\|\\|\\|");
for (String s:test)
   System.out.print(s+"111111111");
于 2020-03-11T14:10:51.133 回答
0

如果您的文本具有||| 在其中,您可以通过以下正则表达式将其拆分为字符串数组

String text = "abc|||123|||#@&"
String[] splitarray = text.split("\\|\\|\\|); // using double slash so | is not interpreted as OR 
for(String s : splitarray)
  {
   System.out.println(s);
   }

输出 :

     abc
     123
     #@&
于 2020-03-11T14:19:56.170 回答