/// <summary> /// Creates an array of frames from a string expression. The expression must be similar to the following format: /// "0,3,7-11,2,5" /// Whitespace is permitted, and commas are optional. /// <param name="input">A string formatted as above, describing the frames to generate.</param> /// </summary> public static int[] ParseFrames(string input) { // Make sure the pattern matches, and alert the user if it doesn't var parse = SyntaxCheck.Match(input); if (!parse.Success) { throw new Exception(string.Format("Invalid format: {0}", input)); } // Get all numbers/ranges in the input string. var frames = new List <int>(); foreach (Match match in GetMatches.Matches(input)) { var range = GetRange.Match(match.Value); if (range.Success) { int from = int.Parse(range.Groups[1].Value); int to = int.Parse(range.Groups[2].Value); // Support ascending and descending ranges if (from < to) { while (from <= to) { frames.Add(from++); } } else { while (from >= to) { frames.Add(from--); } } } else { frames.Add(int.Parse(match.Value)); } } return(frames.ToArray()); }