要是想要后面的几个字符组成的字符串用,subString,要单个的字符,用charAt
解决方案 »
- Spring3+Mybatis+bonecp报的一个Mysql链接问题
- 咨询关于com.enterprisedt.net.ftp.FTPClient 在 Timer下使用的问题
- jsp从mysql读取繁体字乱码
- 大量送分,测试网站的网通与电信问题,网通的朋友多点击多得分。
- 急!!!用Xfire发布服务,如何监视SOAP消息!
- jsp中SQL语句的问题,急!请多多指教
- jsp中怎么得到当前的时候,引入什么类?
- 用java能写出一个邮件服务器吗?Emergency!!!
- java封装json所需的jar包
- 简单邮件系统,HIbernate用户和邮件关系映射问题
- 用网页监控可执行文件是否执行完成
- 郁闷 2000下正常的JDBC连接页面 换到XP+SP2怎么不行
int n = 3;
System.out.println(str.substring(str.length() - n));
String s = "abc";// 得到src中“abc”之后的所有字符串
String result = src.substring(src.indexOf(s)+s.length);// hehehehe// 得到src中“abc”之后的长度为4的字符串String result = src.substring(src.indexOf(s)+s.length , src.indexOf(s)+s.length + 4); //hehe
String s = "abc";
int index = src.indexOf(s)+s.length; // "abc"后的位置// 得到src中“abc”之后的所有字符串
String result = src.substring(index);// hehehehe// 得到src中“abc”之后的长度为4的字符串
String result1 = src.substring(index,index+4); //hehe
substring
public String substring(int beginIndex)
Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string.
Examples: "unhappy".substring(2) returns "happy"
"Harbison".substring(3) returns "bison"
"emptiness".substring(9) returns "" (an empty string)
Parameters:
beginIndex - the beginning index, inclusive.
Returns:
the specified substring.
Throws:
IndexOutOfBoundsException - if beginIndex is negative or larger than the length of this String object.2
substring
public String substring(int beginIndex,
int endIndex)
Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex. Examples: "hamburger".substring(4, 8) returns "urge"
"smiles".substring(1, 5) returns "mile"
Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Returns:
the specified substring.
Throws:
IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.
if(str == null)
return null;
if(count <= 0)
return null;
if(str.length()<=count)
return str;
return str.substring(str.length()-count);
}