How to split a string while ignoring the case of the delimiter?

前端 未结 8 624
梦谈多话
梦谈多话 2021-01-01 09:56

I need to split a string let\'s say \"asdf aA asdfget aa uoiu AA\" split using \"aa\" ignoring the case. to

\"asdf \"
\"asdfget \"
\"uoiu \"
8条回答
  •  一个人的身影
    2021-01-01 10:24

        public static List _Split(this string input,string[] splt)
        {
            List _Result=new List();
            foreach(string _splt in splt)
            {
                if (splt.Count() == 1)
                { 
                    _Result.AddRange(Regex.Split(input, _splt, RegexOptions.IgnoreCase).ToList());
                }
                else 
                {
                    List NewStr = Regex.Split(input, _splt, RegexOptions.IgnoreCase).ToList();
                    foreach(string _NewStr in NewStr)
                    {
                        List NewSplt = splt.ToList();
                        NewSplt.Remove(_splt);
                        return _Split(_NewStr, NewSplt.ToArray());
                    }
                } 
            }
            return _Result;
        } 
    

    then use this function as bellow

    public frmThematicConversation()
    {
        InitializeComponent();
        string str = "a b c d e f g h a b c f a d c b f";
        string[] splt = { "a", "b" };
        List _result = str._Split(splt);
    }
    

提交回复
热议问题