Hey,
After scouring the internet for a while im a bit baffled as to how to display decimal unicode characters within .NET.
I have a small app that collects some strings from a MySQL database, the string are stored as decimal NCRs (i.e H#) and i first of all tried converting them via MySQL so that i could make a new column with a converted string, however that wont work as they are technically 5 characters # & 7 2 ; so it doesnt convert them, so i thought maybe .NET would support it. However i cant find anything out about it, so im just wondering if anyone else has ever had to work with this and how they found a way round it?
I need to be able to add/edit/view the contained strings within the relvent plain text, any help would be great!
Loading
AlanPosted Jul 8, 2008, 2:36 PM
You can replace the decimal NCRs with ordinary unicode characters using a regular expression. For example:
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
string s = "Hello";
Regex r = new Regex(@"&#\d{1,5};");
s = r.Replace(s, MatchEvaluator);
Console.WriteLine(s); // Hello
Console.ReadKey();
}
static string MatchEvaluator(Match m)
{
string temp = m.Value.ToString().Substring(2);
temp = temp.Substring(0, temp.Length - 1);
char c = (char)int.Parse(temp);
return c.ToString();
}
}
LeePosted Jul 9, 2008, 3:53 AM