作者liptonbin (wind)
看板C_Sharp
标题Re: [问题] 请问split问题
时间Wed Sep 5 08:27:03 2007
你好
那请问我的规则要怎麽写 regex.split()
才可以如 1 2 3 4
有空格又有tab 使他能够略过空格和tab等的存入
能够得到word[0]=1
word[1]=2
word[2]=3
word[3]=4
谢谢喔
※ 引述《diamondking (天剑流星)》之铭言:
: ※ 引述《liptonbin (wind)》之铭言:
: : 请问我在c#上面要分割 如41 99 311 16
: : 50 99 300 100
: : 52 10 11 20
: : ...
: : 这四个数字
: : string[] words1 = Regex.Split(str,@"\s+");
: : textBox1.Text = words1[0];
: : textBox2.Text = words1[1];
: : textBox3.Text = words1[2];
: : textBox4.Text = words1[3];
: : 经过以上可能变成
: : textBox1.Text = words1[0]=>41
: : textBox2.Text = words1[1]=>99
: : textBox3.Text = words1[2]=>311
: : textBox4.Text = words1[3];
: : 但是有时候换另外一行又可以
: : 请问为什麽有时候会缺一个
: : 我的regex.split有少写什麽吗?(空格可能有tab键或空格+tab键等)
: : 谢谢喔
: 没实际开编辑器测,不过猜测一下:
: 因为你的规则,1个空格就会被拆,
: 结果你311跟16之前空2格,造成他们之间又多拆出一个空字串。
: 所以16变成在words1[4]。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.69.149.252
1F:推 SmartGoose:StringSplitOptions.RemoveEmptyEntries 09/05 10:10