replace Blank by regular expression - Android java.util.regex

Android examples for java.util.regex:Blank Remove

Description

replace Blank by regular expression

Demo Code

import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.CharacterStyle;
import android.text.style.ForegroundColorSpan;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

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

}

Related Tutorials