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[] SplitIgnoreCase(this string str, char[] separators)
- {
- var splits = new List<string>();
- var lastIndex = 0;
- for (int i = 0; i < str.Length; i++)
- {
- if (separators.Any(c => char.ToLowerInvariant(c) == char.ToLowerInvariant(str[i])))
- {
- splits.Add(str.Substring(lastIndex, i - lastIndex));
- lastIndex = i + 1;
- }
- else if (i == str.Length - 1)
- {
- splits.Add(str.Substring(lastIndex));
- }
- }
- return splits.ToArray();
- }
- }
- public class Program
- {
- public static void Main(string[] args)
- {
- var str = "abXcdXefxgh";
- var splits = str.SplitIgnoreCase(new [] {'x'});
- Console.WriteLine(string.Join(",", splits));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement