trim punctuation from a string - Android java.lang

Android examples for java.lang:String Strip

Description

trim punctuation from a string

Demo Code

import android.text.TextUtils;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static String trimPunct(String str) {

        String tempStr = "";
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if ((chars[i] >= 19968 && chars[i] <= 40869)
                    || (chars[i] >= 97 && chars[i] <= 122)
                    || (chars[i] >= 65 && chars[i] <= 90)) {
                tempStr += chars[i];/* w ww . j ava 2s. c om*/
            }

        }

        return tempStr;
    }

}

Related Tutorials