导航

asp.net使用Substring截取字符串

Posted on 2010-07-03 10:13  ykhi  阅读(16755)  评论(3)    收藏  举报

asp.net变量Substring(参数1,参数2)

截取字串的一部分,参数1为左起始位数,参数2为截取几位。

如:string s1 = str.Substring(0,2);

注意:参数2比实际str的字符串总长度还长,那会报错!

 

String.Substring(int startIndex)
String.Substring(int startIndex, int length)

说明:
返回一个从startIndex开始到结束的子字符串,或返回一个从startIndex开始,长度为length的子字符串。