insert Symbol In String by index - Android java.lang

Android examples for java.lang:String Insert

Description

insert Symbol In String by index

Demo Code

import android.net.Uri;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.StrikethroughSpan;
import android.util.Log;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static String insertSymbolInStrPosition(String srcStr,
            String insertStr, int position) {
        if (emptyOrNull(srcStr)) {
            return "";
        }// ww  w . j a v  a  2 s . com
        String str = "";
        if (position > srcStr.length()) {
            return str;
        }
        StringBuffer showStringBuffer = new StringBuffer(srcStr.length()
                + insertStr.length());
        String tmep = srcStr.substring(position, srcStr.length());
        showStringBuffer.append(srcStr.substring(0, position));
        showStringBuffer.append(insertStr);
        showStringBuffer.append(tmep);
        str = showStringBuffer.toString();
        return str;
    }

}

Related Tutorials