/**
* @创建日期 2013-07-15
* @创建时间 14:25:59
* @版本号 V 1.0
*/
public class CosTest {
public static void main(String[] args) {
String sql = "select * from teacher where id = ? and name = ?" ;
System.out.println(replaceString(sql, "101" , 2 ));
}
public static String replaceString(String str, String rstr, int a) {
String searchStr = "?" ;
int index = str.indexOf(searchStr);
int count = 1 ;
while (count != a) {
index = str.indexOf(searchStr, index + 1 );
count++;
}
return str.substring( 0 , index) + rstr + str.substring(index + 1 );
}
}