// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Text.RegularExpressions; namespace E { public class Program { private static Regex re = new Regex("([A-Z][a-z]+)|([A-Z]+(?=([A-Z][a-z]|[0-9]|$)))|([0-9]+)|(^[a-z]+)", RegexOptions.Compiled); public static List CamelSplit(string s) { List res = new List(); MatchCollection mc = re.Matches(s); foreach(Match m in mc) { res.Add(m.Value); } return res; } public static void Test(string s) { List parts = CamelSplit(s); Console.Write(s + " ->"); foreach(string part in parts) Console.Write(" " + part); Console.WriteLine(); } public static void Main(string[] args) { string[] all = { "Test", "TestTest", "TestTest123", "TestTest123Test", "TestTest1Test2Test3Test", "TestTestTESTTest", "testTest" }; foreach(string one in all) { Test(one); } } } }