Java如何获取一个字符串中子串的位置

string.indexOf("要查找的子串");

//你描述的不是很清楚  请问是一下这个意思吗?

private  static final String CONVERT="ABCDEFGHIJKLMN";
    public static void main(String[] args) {
        test("A");
    }

    public static void test(String a){
        for (int i = 0; i < CONVERT.length(); i++) {
          //判断当前字符串中的单个位置
            if (a.equals(String.valueOf(CONVERT.charAt(i)))) {
              //当前字符串
                System.out.println(CONVERT.charAt(i));
              //获取当前字符串位置
                System.out.println(i+1);
            }
        }
    }

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-03-04
正解......
第2个回答  2015-03-03
对。。。。。。。。