replace Blank \r or \n with regular expression - Android java.util.regex

Android examples for java.util.regex:Blank Remove

Description

replace Blank \r or \n with regular expression

Demo Code

import android.content.Context;
import android.text.TextUtils;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
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("\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        }/*w  w  w.ja  va2s.  c o  m*/
        return dest;
    }

}

Related Tutorials