Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Rextester.Program.Main is the entry point for your code. Don't change it.
- //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace Rextester
- {
- public static class Ext
- {
- public static string FindFirstNeedle(this string str, string[] needles, StringComparison comparison)
- {
- foreach (var needle in needles)
- {
- var i = str.IndexOf(needle, comparison);
- if (i >= 0)
- return needle;
- }
- return null;
- }
- public static string[] SplitIgnoreCase(this string str, string[] separators)
- {
- var splits = new List<string>();
- var needle = str.FindFirstNeedle(separators, StringComparison.OrdinalIgnoreCase);
- while (needle != null)
- {
- var i = str.IndexOf(needle, StringComparison.OrdinalIgnoreCase);
- splits.Add(str.Substring(0, i));
- str = str.Substring(i + needle.Length);
- needle = str.FindFirstNeedle(separators, StringComparison.OrdinalIgnoreCase);
- }
- if (str.Length > 0)
- {
- splits.Add(str);
- }
- return splits.ToArray();
- }
- }
- public class Program
- {
- public static void Main(string[] args)
- {
- var str = "abXYcdxyefXyghKK,oo";
- var splits = str.SplitIgnoreCase(new [] {"xy", "kK"});
- Console.WriteLine(string.Join(",", splits));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement