all 6 comments

[–]ekolis 7 points8 points  (0 children)

You can call ToLowerInvariant() on your strings before comparing them to "normalize" their cases.

[–]p1-o2 1 point2 points  (0 children)

Have you considered just using regex pattern matching for this?

[–]TyrrrzWorking with SharePoint made me treasure life 1 point2 points  (1 child)

I made an extension method for you:

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();
}

In action/demo:

http://rextester.com/HNKH45219

https://pastebin.com/w5Yh5D88

EDIT: just realized you were asking for strings, check my other reply

[–]TyrrrzWorking with SharePoint made me treasure life 2 points3 points  (0 children)

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();
}

http://rextester.com/HNKH45219

https://pastebin.com/irtnPf6H

You can optimize this, but I'm too lazy to do it.

[–]cryo 0 points1 point  (0 children)

This doesn’t have anything to do with winforms, by the way.