Java中substring函数用法

日期:2012-01-07    阅读:94   分类:Java资料

substring

返回一个新字符串,它是此字符串的一个子字符串。该子字符串从指定的 beginIndex 处开始,一直到索引 endIndex - 1 处的字符。因此,该子字符串的长度为 endIndex-beginIndex。

public String substring(int beginIndex, int endIndex)


示例:
 
 "hamburger".substring(4, 8) returns "urge"
 "smiles".substring(1, 5) returns "mile"
 
参数:

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

返回:

指定的子字符串。

异常:

IndexOutOfBoundsException - 如果 beginIndex 为负,或 endIndex 大于此 String 对象的长度,或 beginIndex 大于 endIndex。

本页链接: http://www.scriptlover.com/static/1492-java-substring

标签:

相关文章

网友评论

#1: 2012-1-26 10:18:00 by Ellysrisley#sibfordschool.co.uk

Your answer lifts the itnellgience of the debate.

#2: 2012-1-28 11:53:00 by Amberlykrasnal7171#tlen.pl

That's the best anwser of all time! JMHO

Leave a comment

 required

 required (Not published)

 required