substring方法的使用

来源:互联网 发布:log4j.xml配置打印sql 编辑:程序博客网 时间:2024/05/17 06:02

str=str.substring(int beginIndex);截取掉str从首字母起长度为beginIndex的字符串,将剩余字符串赋值给str;

str=str.substring(int beginIndex,int endIndex);截取str中从beginIndex开始至endIndex结束时的字符串,并将其赋值给str;

substring

public String substring(int beginIndex, int endIndex)

返回一个新字符串,它是此字符串的一个子字符串。该子字符串从指定的

beginIndex 处开始,一直到索引 endIndex - 1 处的字符。因此,该子字符串的长度为 endIndex-beginIndex。

示例:

"hamburger".substring(4, 8) returns "urge"

"smiles".substring(1, 5) returns "mile"

参数:

beginIndex - 开始处的索引(包括)。

endIndex - 结束处的索引(不包括)。

0 0