This question already has answers here:
Convert to UCS2
(4 answers)
Closed 9 years ago.
I am working on a C# based application and came up with this problem of converting a string to UCS2 encoding. Basically, I have to take some text from XML and convert it to UCS2 and write this UCS2 code to a *.dat file.
Is there a way to do this (convert a string to UCS2 encoding) in C#.NET? if not, what are the options then?
Thanks,
There isn't an included Encoding in .NET that will convert the string to UCS-2 encoding. Your best bet is BigEndianUnicode or UTF-16, but these won't work very well.
Related
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);
This question already has answers here:
How can I decode HTML characters in C#?
(10 answers)
Closed 8 years ago.
Im a newbie here.I need help how to decode a html string "👑" to char in c#? it should be show crown character or if its not supported it should show a rectangle.Im working for iOS.
Thank you for all your help.
Try this code to Decode HTML to Unicode Chars
string s = System.Net.WebUtility.HtmlDecode("👑");
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to convert a string to RTF in C#?
I was wondering if there is an easy way convert a string to RTF in C#.
Not only the standard characters but special characters i.e. as €ƒ…†‡ to.
Use the RichTextBox control. You can set it's Text property to a string then get back it's Rtf property.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Binary To Corresponding ASCII String Conversion
I posted a slimier question before but didn't got a correct answer..
my problem is i have a binary string as
00100000011101110110000101101110011101000010000001110100011011110010000001100100011011110111
Which im required to convert to "Normal ASCII String Text"
I used BinaryReader and read and encode System.Text.ASCIIEncoding.ASCII but im getting the same 0101010 string
byte[] bytearray = b.ReadBytes((int)length);
System.Text.Encoding encEncoder = System.Text.ASCIIEncoding.ASCII;
string bb = encEncoder.GetString(bytearray);
any help will be grateful !
first translate the binary string into a byte[] using How could I encode a string of 1s and 0s for transport?
next use the Convert.ToBase64String method to get the actual System.String
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)