Java String Split splitBreaks(String text)

Here you can find the source of splitBreaks(String text)

Description

Splits a String with HTML in it into paragrpahs, based on the <br> tags found.

License

Apache License

Parameter

Parameter Description
text The HTML String to pass in. (hint: use JSoup's .html() method).

Return

A list of paragrpahs in the text. HTML is preserved.

Declaration

public static String[] splitBreaks(String text) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

public class Main {
    /**/*from www.  j  a  va 2  s  .co m*/
     * Splits a String with HTML in it into paragrpahs, based on the &lt;br&gt; tags found.
     * Discards empty lines.
     * 
     * @param text The HTML String to pass in. (hint: use JSoup's .html() method).
     * @return A list of paragrpahs in the text. HTML is preserved.
     */
    public static String[] splitBreaks(String text) {
        //split on <br> tags
        String[] subs = text.split("<br>");
        ArrayList<String> a = new ArrayList<>();

        //trim empty lines
        for (String sub : subs) {
            if (!sub.trim().isEmpty()) {
                a.add(sub);
            }
        }

        return a.toArray(new String[0]);
    }
}

Related

  1. splitArray(String[] srcArr, int start, int end)
  2. splitAt(final String input, final String seperator)
  3. splitAtLastBlank(String s, int width)
  4. splitAttributes(final String dname)
  5. splitAuthors(String source)
  6. splitByTypeAndName(final String s)
  7. splitCamelback(String s)
  8. splitCQLStatements(String source)
  9. splitDateText(String text)