how do I convert text in textBox1 from Hex to Binary and display it in textBox2
I don't even know where to start
To convert an hex string to a binary string you should do :
string binaryValue = Convert.ToString(Convert.ToInt32(hexValue, 16), 2);
Then for the TextBox there is ton of tutorial to make it.
in c# windows application write the simple program ,that program get arabic 1256 character and show to user that ascii code,for that purpose write this code:
string value = textBox1.Text;
int counter = 0;
foreach (byte b in System.Text.Encoding.Default.GetBytes(value.ToCharArray()))
{
label2.Text="Ascii Code="+b.ToString();
counter++;
}
now want to write code get ascii code and show to user arabic 1256 character,how can i write code for that purpose in c#?thanks all.
You can do it this way:
char ch = Convert.ToChar(64);
or with using simply:
char ch = (char)64;
I have a unicode string, let's say "U+660E", and I want to display the corresponding character, which in this case is 明. See this page (ctrl-F to find 明).
My code so far:
string unicodeString = reader.GetString(0);
unicodeString.Trim();
Encoding codepage = Encoding.GetEncoding(950);
Encoding unicode = Encoding.Unicode;
byte[] encodedBytes = codepage.GetBytes(unicodeString);
//unicodeString = Encoding.Convert(codepage, unicode, encodedBytes).ToString();
unicodeString = unicode.GetString(encodedBytes);
richTextBox1.Text = unicodeString;
My output is "⭕㘶䔰�".
Any idea where I went wrong?
.net deals directly with unicode. You do not have to play the encoding games. Just tell the reader if the input is UTF-8 or UTF-16 and then deal with it as a normal string.
richTextBox1.Text = reader.GetString(0)
There's no need to convert to CP-950; C# is Unicode through-and-through. Just input and print as Unicode unless you're outputting to a file that you know has to be CP-950.
i have a text file in which sets of Unicodes are written as
"'\u0641'","'\u064A','\u0649','\u0642','\u0625','\u0644','\u0627','\u0647','\u0631','\u062A','\u0643','\u0645','\u0639','\u0648','\u0623','\u0646','\u0636','\u0635','\u0633','\u0641','\u062D','\u0628','\u0650','\u064E','\u062C','\u0626"
"'\u0622'","'\u062E','\u0644','\u064A','\u0645".
I opened the file and started reading of file by using readline method. I got the above line shown as a line now i want to convert all Unicode to char so that i could get a readable string. i tried some logic but that doesn't worked i stuck with converting string "'\u00641'" to char.
You can extract strings containing individual numbers (using Regex for example), apply Int16.Parse to each and then convert it to a char.
string num = "0641"; // replace it with extracting logic of your preference
char c = (char)Int16.Parse(num, System.Globalization.NumberStyles.HexNumber);
You could parse the line to get each unicode char. To convert unicode to readable character you could do
char MyChar = '\u0058';
Hope this help
What if you do something like this:
string codePoints = "\u0641 \u064A \u0649 \u0642 \u0625";
UnicodeEncoding uEnc = new UnicodeEncoding();
byte[] bytesToWrite = uEnc.GetBytes(codePoints);
System.IO.File.WriteAllBytes(#"yadda.txt", bytesToWrite);
byte[] readBytes = System.IO.File.ReadAllBytes(#"yadda.txt");
string val = uEnc.GetString(readBytes);
//daniel
I need to send a string over TPC/IP, and receiving end will listen for a string and read to a terminator which is ASCII 3. How can I put this in plain text into a textboks?
As Dimitrov said, do something like
textarea.Text += (Char) 3;
or
String text = textarea.Text + (Char) 3;
You don't put this into the textbox, it's a binary character. You will add this to the value of the textbox before sending to the wire:
var ascii = Encoding.ASCII;
byte[] dataToSend = ascii
.GetBytes("Some data from textbox")
.Concat(ascii.GetBytes(new[] { (char)3 }))
.ToArray();
You can also use hexadecimal string literal:
string text = textbox.Text + "\x3";