How to split a string while ignoring the case of t

2020-03-01 02:58发布

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 "

标签: c# .net string
7条回答
冷血范
2楼-- · 2020-03-01 03:37
    public static List<string> _Split(this string input,string[] splt)
    {
        List<string> _Result=new List<string>();
        foreach(string _splt in splt)
        {
            if (splt.Count() == 1)
            { 
                _Result.AddRange(Regex.Split(input, _splt, RegexOptions.IgnoreCase).ToList());
            }
            else 
            {
                List<string> NewStr = Regex.Split(input, _splt, RegexOptions.IgnoreCase).ToList();
                foreach(string _NewStr in NewStr)
                {
                    List<string> 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<string> _result = str._Split(splt);
}
查看更多
登录 后发表回答