Java 截取指定字符串中的某段字符的实现形式
目前整理出来三种形式:
可根据实际需要选择使用
String userNameUrl;
int beginIndex = 0;
int endIndex = 0;
userNameUrl = "454512@hongri@4944115455d9591b274648a06303d910de";
/**
* 方法一:
*/
beginIndex = userNameUrl.indexOf("@")+1;
endIndex = userNameUrl.lastIndexOf("@");
System.out.println(userNameUrl.substring(beginIndex,endIndex));
/**
* 方法二:
*/
System.out.println(userNameUrl.split("@")[1].toString());
/**
* 方法三:
*/
System.out.println(userNameUrl.substring(7, 13));
运行结果:
![143129279.png](http://www.myexceptions.net/img/2015/05/08/143129279.png)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)