zoukankan      html  css  js  c++  java
  • java如何实现替换指定位置的指定字符串的功能

    /**
     * @创建日期 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);
        }
    }
  • 相关阅读:
    bzoj3293 分金币
    考前模板整理
    CF785D Anton and School
    容斥法解决错排问题
    CF1248F Catowice City
    CF1248E Queue in the Train
    CF1244F Chips
    CF1244C The Football Season
    Noip2016Day1T2 天天爱跑步
    Noip2015Day2T3 运输计划
  • 原文地址:https://www.cnblogs.com/stupidMartian/p/6103984.html
Copyright © 2011-2022 走看看