Java String Whitespace Delete deleteWhitespace(CharSequence str)

Here you can find the source of deleteWhitespace(CharSequence str)

Description

delete Whitespace

License

Open Source License

Declaration

public static String deleteWhitespace(CharSequence str) 

Method Source Code

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

public class Main {
    public static String deleteWhitespace(CharSequence str) {
        StringBuilder sb = new StringBuilder(str.length());
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (i > 0 && Character.isWhitespace(c) && Character.isWhitespace(str.charAt(i - 1)))
                continue;
            if (c == '\r' || c == '\n') {
                sb.append(' ');
                continue;
            }/*from  ww  w  .  j  a  v a2  s  . c o m*/
            sb.append(c);
        }
        return sb.toString();
    }
}

Related

  1. deleteWhitespace(CharSequence sequence)
  2. deleteWhitespace(final String s)
  3. deleteWhitespace(final String str)
  4. deleteWhitespace(String s)
  5. deleteWhiteSpace(String s)