Java String Clean toText(String content)

Here you can find the source of toText(String content)

Description

Format the content for search results page

License

Open Source License

Parameter

Parameter Description
content Description of the Parameter

Return

Description of the Return Value

Declaration

public static String toText(String content) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from  w w w  .j  a v a2  s. c  o m
     * Format the content for search results page
     *
     * @param content Description of the Parameter
     * @return Description of the Return Value
     */
    public static String toText(String content) {
        if (content == null) {
            return "";
        }
        StringBuffer sb = new StringBuffer();
        boolean gotSpace = false;
        for (int i = 0; i < content.length(); i++) {
            // Strip extra spaces, all returns
            char a = content.charAt(i);
            if (a == '\r' || a == '\n' || a == '\t' || a == ' ') {
                //01, 14, 15
                if (!gotSpace) {
                    gotSpace = true;
                    sb.append(" ");
                }
            } else {
                sb.append(a);
                gotSpace = false;
            }
        }
        return sb.toString();
    }
}

Related

  1. cleanText(String text)
  2. cleanText(String text)
  3. cleanText(String text)
  4. cleanText(String text)
  5. cleanTextForCSV(final String input)