Break line after a full stop

后端 未结 3 1196
醉梦人生
醉梦人生 2020-12-22 13:02

I am using jsoup to extract content from a webpage. But i want to break the paragraph and display the content on a line by line. This code does not display line by line.Code

相关标签:
3条回答
  • 2020-12-22 13:41

    You print the content paragraph by paragraph in the loop, but you're appending the paragraphs to the StringBuilder without appending line breaks.

    final String lineBreak = System.getProperty("line.separator");
    StringBuilder sb = new StringBuilder();
    
    for (org.jsoup.nodes.Element el : els) {
        sb.append(el.text());
        sb.append(lineBreak);
    }
    
     System.out.println(sb.toString());
    
    0 讨论(0)
  • 2020-12-22 13:52

    if sb or el contains the entire text, you could replace each instance of . with .\n as below

    String el = "your text. your text next line. third line.";
    String[] l = el.split("\\.");
    for (String string : l) {
        System.out.println(string+ ".");
    }
    
    0 讨论(0)
  • 2020-12-22 13:57

    If you want breaks after each line, just write something like that:

    for (org.jsoup.nodes.Element el : els) {
    if(el.text().replace(".",".\n");
        sb.append(el.text());
    
    }
    
    0 讨论(0)
提交回复
热议问题