星空网 > 软件开发 > ASP.net

字符串的分割操作

 static void Main(string[] args)    {      //重复分割符问题的实践和演示      //实践运用的场景||、|同为分割符,2替换为空时出现的|||情况      string content = "1234567890";      string replaceOptions = "1|a||2|||3|||4|c";      Console.WriteLine(replaceContent(content, replaceOptions));      Console.ReadKey();    }

 /**     * 适用于1|a||2|||3|c模式分割,兼容多个|||的情况     **/    public static string replaceContent(string content, string filterWord)    {      ArrayList filterWhiteSpace = new ArrayList();      spliteMuliSymbol(filterWord, ref filterWhiteSpace);      for (int i = 0; i < filterWhiteSpace.Count; i++)      {        string[] replaceArr = filterWhiteSpace[i].ToString().Split('|');        content = Regex.Replace(content, replaceArr[0], replaceArr[1]);      }      return content;    }

 public static void spliteMuliSymbol(string filterWord, ref ArrayList filterWhiteSpace)    {      //判断是否存在替换为空的情况      if (filterWord.Contains("|||"))      {        int whiteSpaceIndex = filterWord.IndexOf("|||");        ArrayList arrHalf = new ArrayList();        string firstHalf = filterWord.Substring(0, whiteSpaceIndex + 1);        string latterHalf = filterWord.Substring(whiteSpaceIndex + 3);        arrHalf.Add(firstHalf);        arrHalf.Add(latterHalf);        for (int i = 0; i < arrHalf.Count; i++)        {          spliteMuliSymbol(arrHalf[i].ToString(), ref filterWhiteSpace);        }      }      else      {        string[] filterWordArray = Regex.Split(filterWord, @"\|\|");        foreach (string temp in filterWordArray)        {          filterWhiteSpace.Add(temp);        }      }    }

 




原标题:字符串的分割操作

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

跨境周报|英国官方宣布延长CE标志使用期限:https://www.kjdsnews.com/a/554685.html
2分钟完成电脑端Facebook双重验证设置:https://www.kjdsnews.com/a/554686.html
速卖通物流再提速,中韩跨境包裹专线可实现5日达:https://www.kjdsnews.com/a/554687.html
亚马逊“黄金90天”是什么?如何引爆流量?:https://www.kjdsnews.com/a/554688.html
Shopee菲律宾退货:GoGo Xpress 正式推出到府退货服务!:https://www.kjdsnews.com/a/554689.html
亚马逊失败Listing案例深度分析!:https://www.kjdsnews.com/a/554690.html
夹江千佛岩景区门票(夹江千佛岩景区门票价格):https://www.vstour.cn/a/411232.html
武陵山大裂谷周围景点 武陵山大裂谷周围景点图片:https://www.vstour.cn/a/411233.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流