第一種

char[] delimiterChars = { ' ' , ',' , '.' , ':' , '\t' };

string text = "one two,three.four:five \ seven";

string[] words = text.Split(delimiterChars);

 

第二種

string text = "one two,three.four:five \ seven";

string[] words = text.Split(new char[5]{' ' , ',' , '.' , ':' , '\t'});

 

但上述沒辦法使用string " " 做分類,c#預設只能使用char ' '

如此遇到中文時可能就沒辦法做切割

因此必須改用

using System.Text.RegularExpressions;
 
string str="abcedfghijk";
string[] sArray=Regex.Split(str,"df",RegexOptions.IgnoreCase); 

文章標籤
全站熱搜
創作者介紹
創作者 noya 的頭像
noya

Noya

noya 發表在 痞客邦 留言(0) 人氣(1,964)