分隔符分隔的字符串

来源:互联网 发布:淘宝刷快递单号 编辑:程序博客网 时间:2024/04/28 21:10

字符串:   strTest   =   "UserName       UserAddr     UserCompany           。。。"  
  注意这个字符串中的空格是不一定的,有时是1到N个空格分隔,有时是1到N个Tab键分隔。。。   
 

string   cutText   =   预设值;  
  System.Text.RegularExpressions.Regex   regex   =   new   System.Text.RegularExpressions.Regex(@"/s+");  
  System.Text.RegularExpressions.MatchCollection   match   =   regex.Matches(cutText);  
  int   stringLen   =   match.Count+1;  
  string[]   s   =   new   string   [stringLen];  
  int   len   =   0;  
  for(int   i=0;i<match.Count;i++)  
  {  
  len   =   i==   0?match[i].Index   -   len:match[i].Index   -   match[i-1].Index   -   match[i-1].Value.Length;  
  s[i]   =   cutText.Substring(0,len);  
  len   =   len   +match[i].Value.Length;  
  cutText   =     cutText.Substring(len);  
   
  }  
  s[stringLen-1]   =   cutText;