读书人

查寻某个字符在字符串中的各个位置记录

发布时间: 2012-09-01 09:33:03 作者: rapoo

查找某个字符在字符串中的各个位置记录

?

? ? ? ? ? ? ? ?//查找某个字符在字符串中的各个位置记录

String sql = " SELECT 1 FROM DUAL WHERE 1=1 AND 2=2 {AND ny = $1} { AND org_no = $2}";

int count = StringUtils.countMatches(sql, "{");

int[] indexs = new int[count];

? ? ? ? int index = 0;

? ? ? ? for(int idx = 0; (idx = sql.indexOf("{", idx)) != -1; idx += "{".length()){

? ?? ?indexs[index++] = idx;

??}

? ? ? ? for(int i:indexs){

? ?? ?System.out.println("----------- index = " + i);

? ? ? ?}

?

?

读书人网 >编程

热点推荐