public static IEnumerable<string> SplitSizes(string str, params int[] sizes) { var start = 0; return sizes.Select(s => { if (start + s > str.Length) return ""; var result = str.Substring(start, s); start += s; return result; }); } void Main() { Console.WriteLine(String.Join("\n", SplitSizes("012345678901234567890123456789", 2, 4, 6, 8, 10))); } /* OUTPUT: 01 2345 678901 23456789 0123456789 */
482200cookie-checkC# split string in fixed sizes (chunks)