replace Blank in string via regular expression - Android java.util.regex

Android examples for java.util.regex:Blank Remove

Description

replace Blank in string via regular expression

Demo Code

import android.text.TextUtils;
import java.math.BigDecimal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

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

}

Related Tutorials