梦想的起点

my shop:http://fashion-for-you.taobao.com/

导航

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 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。

  -----------------------------------------------------以下为rongew更新--------------------------------------------

  C#中 substring() 有两个重载函数

  substring(int a) 用法同上

  substring(int a,int b) b参数应该为截取后的字符串长度

  上面string得用法不只是针对哪种语法

  针对的是c#

  --------------------------------------------------------

  在VB中,如上的substring用法是正确的

  -----------------------------------------------------以下为crazyghost_von更新--------------------------------------------

  以上函数的用法在JavaScript中也是正确的。

  -----------------------------------------------------------------------------------------------------------------------------------

  下面是在javascript中的用法.

  在JS中, 函数声明: stringObject.substring(start,stop)

  start是在原字符串检索的开始位置,stop是检索的终止位置,返回结果中不包括stop所指字符.

 

来自:百度百科

posted on 2010-05-31 15:31  梦想的起点  阅读(2306)  评论(0编辑  收藏  举报