Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have input like "\u0026#2346;\u0026#2366;\u0026#2352;\u0026#2381;\u0026#2360;\u0026#2354;\u0026#2381; \u0026#2319;\u0026#2325;\u0026#2381;\u0026#2360;\u0026#2381;\u0026#2346;\u0026#2381;\u0026#2352;\u0026#2375;\u0026#2360;\u0026#2381;"
How to get actual unicode string from this using c# or vb.net

What I have tried:

using system.text
dim strtem as string=system.text.ascii.getstring()
Posted
Updated 17-Aug-20 22:47pm

1 solution

It depends on exactly what's in your string.

If you paste that string into a C# program, it will give you:
पार्सल् एक्स्प्रेस्
If you then pass that to the System.Net.WebUtility.HtmlDecode function[^], it will return:
पार्सल् एक्स्प्रेस्
which Google translates as:
Colis express
However, if the string comes from an external source, and contains the literal \u0026 characters, then you'll need to decode them first. There are several examples of how to do that in this SO thread:
c# - How do I convert Unicode escape sequences to Unicode characters in a .NET string? - Stack Overflow[^]

For example:
C#
static string Decode(string input)
{
    string html = System.Text.RegularExpressions.Regex.Replace(input, @"\\u[0-9A-F]{4}", match => ((char)int.Parse(match.Value.Substring(2), System.Globalization.NumberStyles.HexNumber)).ToString(), RegexOptions.IgnoreCase);
    return System.Net.WebUtility.HtmlDecode(html);
}

...

string input = @"\u0026#2346;\u0026#2366;\u0026#2352;\u0026#2381;\u0026#2360;\u0026#2354;\u0026#2381; \u0026#2319;\u0026#2325;\u0026#2381;\u0026#2360;\u0026#2381;\u0026#2346;\u0026#2381;\u0026#2352;\u0026#2375;\u0026#2360;\u0026#2381;"
string output = Decode(input);
 
Share this answer
 
Comments
Sandeep Mewara 18-Aug-20 5:01am    
I think this is what OP asked. +5. I will remove my answer to avoid confusion.
Chitranjan Pd Asthana 18-Aug-20 5:49am    
Thanks found the exact string

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