if (color1.indexOf("#") >= 0)//if the string has %23 which is "#"
{
color = "#";//add it in as a usable character
color += color1.substring((color1.indexOf("\x23") + 1));//add in the color code
}
ie. "%23" should be either "\x23" or "#" and the substring adder should be 1, not 3.
There should really be some more checking of the input, but at least this works as the original was intended.