业务小场景:截取指定输入内容的某个特殊符号前的字符串,比如 要求输入 张三_1371606XXXX
这么一个格式,我们要截取他的姓名,于是就引出了下面这篇文章

    public static void main(String[] args) {
        String st = "sss--xxx";
        System.out.println("substring" +
           "返回从索引0开始,第一次出现字符串ss的全部字符串:"+st.substring(0, st.indexOf("-")));
        System.out.println("indexOf" +
           "返回从索引1开始的字符串ss的结束索引位置:"+st.indexOf("ss",1));
        System.out.println("indexOf" +
           "返回最小索引值(int),未找到则返回-1:"+st.indexOf("z"));
    }


怎么办,不写点感觉身上有蚂蚁在爬!