substring的用法

1.java和javascript中的用法相似

java中substring的用法:

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

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

javascript中substring的用法:

stringObject.substring(start,stop)

返回值:
一个新的字符串,该字符串值包含 stringObject 的一个子字符串,其内容是从 start 处到 stop-1 处的所有字符,其长度为 stop start

   说明:substring() 方法返回的子串包括 start 处的字符,但不包括 stop 处的字符。

     如果参数 start  stop 相等,那么该方法返回的就是一个空串(即长度为 0 的字符串)。如 果 start  stop 大,那么该方法在提取子串之前会先交换这两个参数。

提示和注释:重要事项: slice()  substr() 方法不同的是,substring() 不接受负的参数。

2.c#中独特的用法

String.Substring 方法 (Int32, Int32)

参数

startIndex
类型:System.Int32
此实例中子字符串的起始字符位置(从零开始)。
length
类型:System.Int32
子字符串中的字符数。

返回值

类型:System.String
与此实例中在 startIndex 处开头、长度为 length 的子字符串等效的一个字符串,如果 startIndex 等于此实例的长度且 length 为零,则为 Empty
原文地址:https://www.cnblogs.com/jinTaylor/p/3630931.html