replace all "\r" and "\n" with " " from the argument, then return the fixed result. - Android java.lang

Android examples for java.lang:String Replace

Description

replace all "\r" and "\n" with " " from the argument, then return the fixed result.

Demo Code

import android.content.Context;
import android.graphics.Paint;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    /***//from  w  w w.  j  ava2  s .  c o  m
     * It replace all "\r" and "\n" with " " from the argument, then return the fixed
     * result.
     * 
     * @param text the string to be modified.
     * @return the modified string
     * @author Denverhan
     */
    public static String removeNextLine(String text) {
        if (StringUtil.isEmpty(text)) {
            return text;
        }

        Pattern p = Pattern.compile("\r|\n");
        Matcher m = p.matcher(text);
        String result = m.replaceAll(" ");

        return result;
    }

}

Related Tutorials