substring,
substring,
public String substring(int beginIndex)
返回一个新的字符串,它是此字符串的一个子字符串。该子字符串始于指定索引处的字符,一直到此字符串末尾。
例如:
"unhappy".substring(2) returns "happy"
"Harbison".substring(3) returns "bison"
"emptiness".substring(9) returns "" (an empty string)
参数:
beginIndex - 开始处的索引(包括)。
返回:
指定的子字符串。
抛出:
IndexOutOfBoundsException - 如果 beginIndex 为负或大于此 String 对象的长度。
-------------------------------------------------------------------------------- ------------------------------------------
substring
public String substring(int beginIndex, int length)
返回一个新字符串,它是此字符串的一个子字符串。该子字符串从指定的 beginIndex 处开始, length:表示子字符串的长度。
示例:
"hamburger".substring(4,8) returns "urge"
"smiles".substring(1,5) returns "mile"
参数:
beginIndex - 开始处的索引(包括)。
endindex 结尾处索引(不包括)。
返回:
指定的子字符串。
抛出:
IndexOutOfBoundsException - 如果 beginIndex 为负,或length大于字符串长度。
---------------------------------------------------------------------------------------------------------------------------------------------
js中substr与substring的区别
substr(start[,length])表示从start位置开始取length个字符串
substring(start,end)表示从start,到end之间的字符串,包括start位置的字符但是不包括end位置的字符
对Js的substring还有几点要说明
start不一定就是第一个参数,end也不一定就是第二个参数,substring(3,1)时,开始位置是1,结束位置是3;
<script type="text/javascript">
var str="Hello world!"
document.write(str.substring(3,1)); //el
</script>
相关文章
- 暂无相关文章
用户点评