作者diamondking (天剑流星)
看板C_Sharp
标题Re: [问题] 请问split问题
时间Wed Sep 5 00:34:03 2007
※ 引述《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: 218.167.120.203