[代码]通用的以字符串为分隔符的Split方法

static public string [] SplitString(string str,string separator)
{
      
string tmp = str;
      Hashtable ht 
= new Hashtable();
      
int i = 0;
      
int pos = tmp.IndexOf(separator);
      
while(pos != -1)
      
{
         ht.Add(i,tmp.Substring(
0,pos));
         tmp 
= tmp.Substring(pos+separator.Length);
         pos 
= tmp.IndexOf(separator);
         i
++;
      }

      ht.Add(i,tmp);
      
string [] array = new string[ht.Count];
      
for(int j=0;j<ht.Count;j++)
         array[j] 
= ht[j].ToString();
            
         
return array;
}
posted @ 2005-12-22 08:56  Elaine Shi  阅读(1314)  评论(1编辑  收藏  举报