string split字符串多字符分割 c#字符串扩展

来源:互联网 发布:unity3d 视频播放 编辑:程序博客网 时间:2024/05/17 00:55

初步实现此功能,未进行效率测试,共享给有需要的人:

  /// <summary>
  /// 字符串分割split
  /// </summary>
  /// <param name="str">分割字符 串</param>
  /// <param name="strSplit">分割字符</param>
  /// <returns></returns>
  public string[] stringExtSplit(string str, string strSplit)
  {
   ArrayList arrayList = new ArrayList();
   string tmpStr = "";
   while (str.IndexOf(strSplit) > -1)
   {
    tmpStr = str.Substring(0, str.IndexOf(strSplit));
    str = str.Substring(str.IndexOf(strSplit)+strSplit.Length);
    arrayList.Add(tmpStr);
   }
   arrayList.Add(str);
   
   return (string[])arrayList.ToArray(typeof(string));

  }

原创粉丝点击