We have a web app which uses the ISO-8859-1 character set. Occationaly users have 'strange' names which contain characters like Š (html encoded here for your convenience). We store this in our database, but we can't display it correctly.
What is the best way of dealing with this? I'm thinking I should automatically convert characters outside the character set with its HTML Entity number encoding ( Š to Š)
But I'm having problems finding out how to do this automatically (without using a table of all values).
This code works for extended ASCII characters like 'å' (that are present in ISO-8859-1). I would like to do the same with other characters. Is there a pattern in these HTML entity encoding values I can use?
unsigned int c;
for( int i=0; i < html.GetLength(); i++)
{
c = html[i];
if( c > 255 || c < 0 )
{
CString orig = CString(html[i]);
CString encoded = "&#";
encoded += CTool::String((byte)c);
encoded += ";";
html.Replace(orig, encoded);
}
}