使用substring()对字符串进行截取:

/**
* str.indexOf()查找下标
* substring();//字符串截取
* length();//字符串长度
* */
@Test
public void funB() {
String mail = "[email protected]";
int aa = mail.indexOf("@");
System.out.println("@所在位置:"+aa);
System.out.println("mail长度:"+mail.length());
System.out.println("邮箱用户名:"+mail.substring(0, aa));
System.out.println(mail.substring(aa+1));
System.out.println("邮箱用户名:"+mail.substring(aa, mail.length()));
}

  

05-11 20:44