看板 C_Sharp 關於我們 聯絡資訊
你好 那請問我的規則要怎麼寫 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
SmartGoose:StringSplitOptions.RemoveEmptyEntries 09/05 10:10