分割字符串和截取字符串:split 和substring

时间:2023-12-23 22:29:55

//按“,”截取字符串

String id="123123,234534,453456";

String[] idArry = id.trim().split(",");
for(String nid:idArry){
System.out.println(nid);
}

打印出的值为:123123

234534

453456

//分隔符:substring

String returnResult= "13123123";

String subresult = returnResult.substring(1, returnResult.length() - 1);

subresult的值为“312312”