|
String中文字替換<遞歸算法> private static String resSql = ""; /** * @param 替換sql 語句中以startWith開頭, 以endWith結(jié)尾的String 并且得到中間的String * @sql 進(jìn)行替換的String * @startWith 以XX開頭 * @endWith 以XX結(jié)尾 * @replaceWith 替換成文字 * */ private static String replaceParams(String sql, String startWith, String endWith, String replaceWith) { resSql = sql; List<String> paramList = new ArrayList<String>(); if (sql.indexOf(startWith, 0) > 0) { int startNUm = resSql.indexOf(startWith, 0); int endNum = resSql.indexOf(endWith, startNUm); String paramName = resSql.substring(startNUm, endNum); paramName = paramName.substring(1, paramName.length()); paramList.add(paramName); resSql = resSql.replace(startWith + paramName + endWith, replaceWith); } else resSql = ""; if (resSql.indexOf(startWith) > 0) replaceParams(resSql, "{", "}", "?"); return resSql; } |
|
|