To parse a Hex you would do something like this:
var hex = "0xFFFFFF";
uint color;
if(uint.TryParse(hex, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out color))
{
//Parsing ok
}else{
color = 0; //Parsing failed
}
I dont know your string above, so i am unsure how to extract the hex from it.
EDIT #1:
As i understand you want to parse this string
<font color=**"&amp;****amp;**;**amp;#x23;**336699">Hi How ARE YOU</font>
and produce thie string
<font color=0x0987AF>Hi How ARE YOU</font>
I dont know how your colorcode is created, so i can not parse it.
It it is embeded into a regular language you can use regular expressions to fit the important peaces together and parse those results. If it is HTML or something simmilar you can not use regex and should instead iterate through it character by character. In that case utilize the StringBuilder to keep your code fast.
once you have all stringpeaces together you can parse them individually, calculate the color and then use String.Format(""{0:X06}"", color)
to output it as a hex again.
EDIT #2:
I do not know the encoding of that color string, so i can only give a rough estimate of how i would parse that.
I assume that the last digits in that string are the color and everything else is just noise. So this
<font color=**"&amp;****amp;**;**amp;#x23;**336699">Hi How ARE YOU</font>
should transform into this
<font color="&336699">Hi How ARE YOU</font>
I dont show the first part of isolating the color string, but i want to note that you should not try to use regular expressions on html. Rather go through it character by character like you would with a mathematical expression.
String examplestring = @"color=**""&amp;****amp;**;**amp;#x23;**336699""";
Console.WriteLine(examplestring);
String lastsixnumbers = examplestring.Substring(examplestring.Length - 7, 6);
Console.WriteLine(lastsixnumbers);
String final = String.Format("color=\"#{0}\"", lastsixnumbers);
Console.WriteLine(final);
Console.ReadKey();
Is this helpful? If not then my understanding of the colorcode could be wrong - could you then provide more actually matching results using the color codes or even better provide me with the knowledge how the colors are encoded.