using System.Collections.Generic;
List<string> myColors = new List<string>();
var expectedColor = SearchNextAvaliable(color, myColors);
Console.WriteLine("Expected " + expectedColor);
private string SearchNextAvaliable(string color, List<string> myColors)
var returnColor = string.Empty;
if (RecursiveGetNextColor(myColors, color, out returnColor))
private bool RecursiveGetNextColor(List<string> myColors, string targetColor, out string returnColor)
var newLast = string.Empty;
newLast = NextColor(targetColor, 0);
if (targetColor.Equals(newLast, StringComparison.CurrentCultureIgnoreCase))
if (myColors.BinarySearch(newLast) >= 0 && newLast != "ZZZZZZZZZ")
return RecursiveGetNextColor(myColors, newLast, out returnColor);
private string NextColor(string color, int lastCharPosition)
var stringLength = color.Length;
lastChar = char.Parse(color.Substring(stringLength - 1).ToUpper());
if (lastCharPosition < 9)
return NextColor(color, lastCharPosition + 1);
return string.Format("{0}0", color);
if (lastChar >= 65 || lastChar >= 48 && lastChar <= 57)
return color.Substring(0, stringLength - 1 + lastCharPosition) + (char)lastChar;
return string.Format("{0}0", color);
color = color.Replace(" ", string.Empty);
stringLength = color.Length;
color = TruncateColor(color);
if (color != "ZZZZZZZZZ")
return NextColor(color, 0);
private string TruncateColor(string color)
color = color.Replace(" ", "");
var ItemMasterColorColumnMaxLength = 9;
if (color.Length > ItemMasterColorColumnMaxLength)
var halfTheLength = ItemMasterColorColumnMaxLength / 2;
color = color.Substring(0, halfTheLength) + color.Substring(color.Length - halfTheLength);