Java Regex String Replace Whitespace replaceBlank(String str)

Here you can find the source of replaceBlank(String str)

Description

replace Blank

License

Open Source License

Declaration

public static String replaceBlank(String str) 

Method Source Code

//package com.java2s;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    public static String replaceBlank(String str) {
        if (str != null) {
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(str);
            str = m.replaceAll("");
        }/*from w  w  w.  j  av a 2s  .c  om*/
        return str;
    }

    public static String replaceAll(String s, String sf, String sb) {
        int i = 0, j = 0;
        int l = sf.length();
        boolean b = true;
        boolean o = true;
        String str = "";
        do {
            j = i;
            i = s.indexOf(sf, j);
            if (i > j) {
                str += s.substring(j, i);
                str += sb;
                i += l;
                o = false;
            } else {
                str += s.substring(j);
                b = false;
            }
        } while (b);
        if (o) {
            str = s;
        }
        return str;
    }
}

Related

  1. replaceBlank(String str)
  2. replaceBlank(String str)
  3. replaceBlank(String str)
  4. replaceWhitespace(final String value, final boolean stripExtras)
  5. replaceWhitespace(final String value, final boolean stripExtras)
  6. replaceWhitespace(String searchTerm)