remove All Token from within a string - Android java.lang

Android examples for java.lang:String Replace

Description

remove All Token from within a string

Demo Code

import android.text.TextUtils;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static String removeAllToken(String originalString, String token) {
        int index = originalString.indexOf(token);
        while (index >= 0) {
            String str1 = originalString.substring(0, index);
            String str2 = originalString.substring(index + token.length());
            if (index == 0) {
                originalString = str2;/*  w  w w.j a va  2s .co  m*/
            } else if (index + token.length() == originalString.length()) {
                originalString = str1;
            } else {
                originalString = str1 + str2;
            }
            index = originalString.indexOf(token);
        }
        return originalString;
    }

}

Related Tutorials