Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi,

I have this:
C#
string str =  "& #1047;& #1076;& #1088;& #1072;& #1074;& #1077;& #1081;, & #1089;& #1074;& #1103;& #1090;"


so I want my output like that:

"Здравей, свят"

Here is the website:
http://vivenciandoti.blogspot.pt/2001/01/tabela-de-caracteres-especiais-html.html[^]

and how I can convert it in my winform app?
So I hope you understand my question...

Regards,
KZ
Posted
Comments
Ganesan Senthilvel 23-May-12 10:35am    
Give more information on the target output type.
Killzone DeathMan 23-May-12 11:02am    
Example:
display the code to convert the int 65 to A.
Console.WriteLine("I typed '" + (char)65 + "'!);

Output:

I typed '65'!

But I want this output:

I typed 'A'!
Killzone DeathMan 23-May-12 10:58am    
I try:
Convert.ToChar("& #1047;");
But error:
"String must be exactly one character long."

The Regex.Matches method can be used to extract the decimal values of the characters and then Select method of IEnumerable can be used to convert each decimal value into character and then a string can be constructed from the array of chars as shown below:

C#
string str =  "& #1047;& #1076;& #1088;& #1072;& #1074;& #1077;& #1081;, & #1089;& #1074;& #1103;& #1090;";

MatchCollection charNums = Regex.Matches(str,@"(?<=#\s*)\d+(?=\s*)", 
                                    RegexOptions.CultureInvariant);
string strFinal = new string(charNums.OfType<Match>().Select (
                            m => (char)Convert.ToInt32(m.Value)).ToArray());
Console.WriteLine (strFinal);

Output
Здравейсвят
 
Share this answer
 
v3
Comments
Killzone DeathMan 23-May-12 11:10am    
Ahahaha Here is my boy!!!! It works, it works!!!!! Yupi
You are hired VJ Reddy, I love you! ahahaha
VJ Reddy 23-May-12 11:15am    
You're welcome and thank you for accepting the solution :)
Killzone DeathMan 23-May-12 11:22am    
One more question...how can I have your mail? You can help me for so much more things...
El_Codero 23-May-12 11:28am    
Nice solution reddy.5ed!
Killzone DeathMan 23-May-12 11:34am    
Yeah really nice solution... :)
Not wrapped in a nice tidy method, but this also works:

C#
string str = "& #1047;& #1076;& #1088;& #1072;& #1074;& #1077;& #1081;, & #1089;& #1074;& #1103;& #1090;";

 str = Regex.Replace(str, @"& #(\d+);", m => ((char)int.Parse(m.Groups[1].Value)).ToString());


Output:
Здравей, свят
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 23-May-12 12:42pm    
My 5.
--SA
Vishal3650 19-Sep-13 8:18am    
good work great!
its very helpful.

chris ross 2
thanks buddy
Wendelius 23-May-12 14:42pm    
My 5.
Maciej Los 24-May-12 12:02pm    
Good work, my 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900