C#的SubString(int start,int end);
C#的SubString();
例子:
string str = "i am a girl";
string temp = str.Substring(2,2);//从索引2开始,截取长度为2的字符串(索引的起始下表是0)
//结果是 am
注意:截取的长度不能比剩下的字符串还要长,否则会报错:
Substring: index and length must refer to a location within the string
错误的原因是超出了字符串的长度,如上面的例子:string temp = str.Substring(2,10);//这样就会报错