C#中Substring具体怎么用?(本人是菜鸟复杂的例子看不懂)
3 回答
![?](http://img1.sycdn.imooc.com/5458477300014deb02200220-100-100.jpg)
临摹微笑
TA贡献1982条经验 获得超2个赞
用于截取字符窜的某一部分,string.substring(param1,param2),param1是指定字符窜从零开始的索引,param2是指定要截取的字符个数,比如:
string str1 = "abcdefg" ; srting str2 = str1.substring(0,2);此时str2就是ab str2 = str1.substring(2,2);此时str2就是cd |
![?](http://img1.sycdn.imooc.com/533e4c9c0001975102200220-100-100.jpg)
跃然一笑
TA贡献1826条经验 获得超6个赞
Substring() 求子串
该函数重载,有两种参数情况:
1. 一个参数,int型,表示这个子串在原串中的起始位置,一直到原串的末尾;
2. 两个参数,int型,表示这个子串在原串中的起始位置,和这个子串的长度; string str = "Hello, world!";
string cnt1 = "";
string cnt2 = "";
cnt1 = str.Substring(1); //cnt1=="ello, world!"
cnt2 = str.Substring(1, 2); //cnt2=="el"
![?](http://img1.sycdn.imooc.com/545850ee0001798a02200220-100-100.jpg)
紫衣仙女
TA贡献1839条经验 获得超15个赞
例如:string s="hello word!";s.substring(2); 一个参数表示从第几位开始到末尾截取字符串.s.substring(2,8); 两个参数从第几位到第几位截取字符串. 字符串下标都是从0开始.
- 3 回答
- 0 关注
- 193 浏览
添加回答
举报
0/150
提交
取消