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

前端 未结 8 480
梦谈多话
梦谈多话 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:19

    My answer isn't as good as Noldorin's, but I'll leave it so people can see the alternative method. This isn't as good for simple splits, but it is more flexible if you need to do more complex parsing.

    using System.Text.RegularExpressions;
    
    string data = "asdf aA asdfget aa uoiu AA";
    string aaRegex = "(.+?)[aA]{2}";
    
    MatchCollection mc = Regex.Matches(data, aaRegex);
    
    foreach(Match m in mc)
    {
        Console.WriteLine(m.Value);
    }
    

提交回复
热议问题