Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. //Rextester.Program.Main is the entry point for your code. Don't change it.
  2. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text.RegularExpressions;
  8.  
  9. namespace Rextester
  10. {
  11.     public static class Ext
  12.     {      
  13.         public static string[] SplitIgnoreCase(this string str, char[] separators)
  14.         {
  15.             var splits = new List<string>();
  16.             var lastIndex = 0;
  17.             for (int i = 0; i < str.Length; i++)
  18.             {
  19.                 if (separators.Any(c => char.ToLowerInvariant(c) == char.ToLowerInvariant(str[i])))
  20.                 {
  21.                     splits.Add(str.Substring(lastIndex, i - lastIndex));
  22.                     lastIndex = i + 1;
  23.                 }
  24.                 else if (i == str.Length - 1)
  25.                 {
  26.                     splits.Add(str.Substring(lastIndex));
  27.                 }
  28.             }                
  29.             return splits.ToArray();
  30.         }
  31.     }  
  32.    
  33.     public class Program
  34.     {
  35.         public static void Main(string[] args)
  36.         {
  37.             var str = "abXcdXefxgh";
  38.             var splits = str.SplitIgnoreCase(new [] {'x'});
  39.             Console.WriteLine(string.Join(",", splits));
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement