cut out string that looks suspicious - Android java.lang

Android examples for java.lang:String Shorten

Description

cut out string that looks suspicious

Demo Code

import android.content.Context;
import android.content.res.AssetManager;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main{

    /**//from ww w  .  ja v a  2s . c o m
     * cut out anything that looks suspicious
     * @param s
     * @return
     */
    public static String massageString(String s) {
        StringBuffer sb = new StringBuffer(s.length());
        for (int ich = 0; ich < s.length(); ich++) {
            char ch = s.charAt(ich);
            if (Character.isLetterOrDigit(ch)) {
                sb.append(ch);
            } else if (Character.isWhitespace(ch)) {
                sb.append(' ');
            } else {
                sb.append(' ');
            }
        }
        return sb.toString();
    }

}

Related Tutorials