How to decoding UTF8 encoded value in C#? [duplicate] - c#

This question already has answers here:
How do I decode a URL parameter using C#?
(5 answers)
Closed 7 years ago.
Cookie value stored in UTF8 Encoded value Wuce%C3%B1o. Acutual value is Wuceño. How to convert the encoded value in decode to get Wuceño in c#?

Try WebUtility.UrlDecode:
string s = WebUtility.UrlDecode("Wuce%C3%B1o");
or HttpUtility.UrlDecode:
string s = HttpUtility.UrlDecode("Wuce%C3%B1o");

Related

Efficiently converting a string to a byte array in C# (Not with Encoding) [duplicate]

This question already has answers here:
Converting string to byte array in C#
(20 answers)
Closed 4 years ago.
How can I convert the string "0100" to a byte array {0,1,0,0} without using Convert.ToByte() on each element? The string may only contain characters 0 thru 9.
With linq
var bytes = "0100".Select(x => (byte)(x - '0')).ToArray();

How to convert \uXXXX\uXXXX to plain text by C# [duplicate]

This question already has answers here:
Getting unicode string from its code - C#
(3 answers)
Convert a Unicode string to an escaped ASCII string
(9 answers)
Closed 7 years ago.
string unicode = "\u0e23\u0e32";
How to convert \uXXXX\uXXXX to plain text by C#

How to convert UTF-8 to string in C# [duplicate]

This question already has answers here:
How to Decode "=?utf-8?B?...?=" to string in C#
(4 answers)
Closed 8 years ago.
H, I have this string that I got from a htm file
String s = "%u05d9%u05e8%u05d5%u05e9%u05dc%u05d9%u05dd"
It is in UTF8 code value Hebrew characters and I want to convert it to a real string that I can write to a file and have meaning (not just the code value of the char set).
I tried to do this but it does not work -
byte[] bytes = Encoding.UTF8.GetBytes(s);
addr = Encoding.UTF8.GetString(bytes);
The original string might have been UTF-8 encoded, but this is irrelevant because what you have right now is an URL encoded string. You can decode it using HttpUtility.UrlDecode:
System.Web.HttpUtility.UrlDecode("%u05d9%u05e8%u05d5%u05e9%u05dc%u05d9%u05dd")
returns ירושלים
try
System.Net.WebUtility.UrlDecode(s);

How to convert the following text into a proper string in C#? [duplicate]

This question already has answers here:
How can I decode HTML characters in C#?
(10 answers)
Closed 7 years ago.
How to convert the following text into a proper string in C#?
<IconStyle xmlns="http://earth.google.com/kml/2.0"><color>FFFFFFFF</color><scale>1.0</scale><Icon><href>root://icons/palette-5.png</href><x>192</x><y>192</y><w>32</w><h>32</h></Icon></IconStyle><LabelStyle xmlns="http://earth.google.com/kml/2.0"><scale>0</scale></LabelStyle><BalloonStyle xmlns="http://earth.google.com/kml/2.0"><text>$[description]</text><color>FFFFFFFF</color></BalloonStyle>
Forgot to mention the important catch:how to convert the string in a console application in c#?
That is HTML encoded, so:
HttpUtility.HtmlDecode(myHtmlEncodedString);
Reference: http://msdn.microsoft.com/en-us/library/7c5fyk1k.aspx
HttpUtility.HtmlDecode(string)

How to Convert Hex String to Hex Number [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How do I convert hex string into signed integer?
example:"3A" convert to 0x3A,thanks a lot!
Convert.ToInt32("3A", 16)
int.Parse("3A",NumberStyles.HexNumber)
or
long.Parse("3A",NumberStyles.HexNumber)
etc...

Categories