remove Blank character from string - Android java.lang

Android examples for java.lang:Character

Description

remove Blank character from string

Demo Code

import android.text.TextUtils;
import java.util.Locale;
import java.util.UUID;

public class Main{

    public static String removeBlanks(String content) {
        if (content == null) {
            return null;
        }//from www . j av a  2 s  .co  m
        StringBuilder buff = new StringBuilder();
        buff.append(content);
        for (int i = buff.length() - 1; i >= 0; i--) {
            if (' ' == buff.charAt(i) || ('\n' == buff.charAt(i))
                    || ('\t' == buff.charAt(i)) || ('\r' == buff.charAt(i))) {
                buff.deleteCharAt(i);
            }
        }
        return buff.toString();
    }

}

Related Tutorials