sub是子的意思,substring是指从string字符串中取其一个子串。
例如: string str1 = "ajsdjjajsd";
string str2 = str1.Substring(2, 2);//注意str1字符串的第一个字符的序号为0,从序号为2的字符开始,连续去两个字符,组成字符串赋值给str2
Console.WriteLine(str2);
那么结果就是:sd
从子字符串从指定的字符位置开始且具有指定的长度。
从此实例检索子字符串。子字符串从指定的字符位置开始且具有指定的长度。
public string Substring(
int startIndex,
int length
)
参数
startIndex
类型: System ..::.Int32
此实例中子字符串的起始字符位置(从零开始)。
length
类型: System ..::.Int32
子字符串中的字符数。
String str1 = "abcdefg";
str1.Substring(2,3); //返回从第3个字符开始的长度为3的子字符串,结果是字符串"cde"