replace string Token With another token - Android java.lang

Android examples for java.lang:String Replace

Description

replace string Token With another token

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 replaceTokenWith(String originalString,
            String token, String replacement) {
        int index = originalString.indexOf(token);
        if (index != -1) {
            String ret = originalString.substring(0, index) + replacement
                    + originalString.substring(index + token.length());
            return ret;
        } else {/*from   www .  jav  a2s  .  c  o m*/
            return originalString;
        }
    }

}

Related Tutorials