欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > > 文章正文

取子字符串的函数substring(),函数substring

来源: javaer 分享于  点击 14335 次 点评:70

取子字符串的函数substring(),函数substring


substring(int   index)   从第index个字开始到最后(String从0开始计数)
substring(int   beginIndex,   int   endIndex)   从第index个字开始到第endIndex(String从0开始计数,这里不包括第endIndex个字符) 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   endIndex)返回一个新字符串,它是此字符串的一个子字符串。该子字符串从指定的   beginIndex   处开始,一直到索引   endIndex   -   1   处的字符。因此,该子字符串的长度为   endIndex-beginIndex。  
示例:  

  "hamburger ".substring(4,   8)   returns   "urge "
  "smiles ".substring(1,   5)   returns   "mile "
 
参数:
beginIndex   -   开始处的索引(包括)。
endIndex   -   结束处的索引(不包括)。  
返回:
指定的子字符串。  
抛出:  
IndexOutOfBoundsException   -   如果   beginIndex   为负,或   endIndex   大于此   String   对象的长度,或   beginIndex   大于   endIndex。

相关文章

    暂无相关文章

用户点评