Java tutorial
//package com.java2s; public class Main { public static String replaceByPosition(String str, String replaceStr, String expressStr, int position) { StringBuffer sb = new StringBuffer(); String[] c = str.split(expressStr); for (int i = 0; c != null && i < c.length; i++) { if (i == position) { c[i] = str; } sb.append(c[i]); } return sb.toString(); } }