Problems with Converting Sting to Byte Array

  • Thread starter Thread starter Max Gattringer
  • Start date Start date
M

Max Gattringer

I have written a little programm, which converts normal Text into Unicode
Bytes - nothing special, but i tried to creat 2nd Encoder which converts
strings(numbers) in a textBox (strings which i had converted from
UnicodeString to Bytes) to a UnicodeString.
<textbox Text : 0770>
->>> byte[] <--- I want the numbers in the Array
---->>>> as UnicodeString: M

Thx
PS: Please ignore the broken English - It's hard to discribe my problem..
 
byte [] unicodeBytes = new byte[] {77, 0, 79, 0, 77, 0};
string s = System.Text.Encoding.Unicode.GetString(unicodeBytes);
 
I need this dynamically -> not just for the number 770 - >

string a = textBox1.Text;

-> i want this string: a(numbers) in the byte Array!
byte [] unicodeBytes = new byte[] {77, 0, 79, 0, 77, 0};
string s = System.Text.Encoding.Unicode.GetString(unicodeBytes);

byte [] unicodeBytes = new byte[] {77, 0, 79, 0, 77, 0};
string s = System.Text.Encoding.Unicode.GetString(unicodeBytes);

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com



Max Gattringer said:
I have written a little programm, which converts normal Text into Unicode
Bytes - nothing special, but i tried to creat 2nd Encoder which converts
strings(numbers) in a textBox (strings which i had converted from
UnicodeString to Bytes) to a UnicodeString.
<textbox Text : 0770>
->>> byte[] <--- I want the numbers in the Array
---->>>> as UnicodeString: M

Thx
PS: Please ignore the broken English - It's hard to discribe my problem..
 
That was an example. Here's some that can work for you. You need to add your
error handling though.

string[] stringNumbers = this.textBox1.Text.Split(' ');
byte[] unicodeBytes = new byte[stringNumbers.Length];
for (int i = 0; i < stringNumbers.Length; i++) {
unicodeBytes = byte.Parse(stringNumbers);
}

-mike
MVP

Max Gattringer said:
I need this dynamically -> not just for the number 770 - >

string a = textBox1.Text;

-> i want this string: a(numbers) in the byte Array!
byte [] unicodeBytes = new byte[] {77, 0, 79, 0, 77, 0};
string s = System.Text.Encoding.Unicode.GetString(unicodeBytes);

byte [] unicodeBytes = new byte[] {77, 0, 79, 0, 77, 0};
string s = System.Text.Encoding.Unicode.GetString(unicodeBytes);

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com



Max Gattringer said:
I have written a little programm, which converts normal Text into Unicode
Bytes - nothing special, but i tried to creat 2nd Encoder which
converts
strings(numbers) in a textBox (strings which i had converted from
UnicodeString to Bytes) to a UnicodeString.
<textbox Text : 0770>
->>> byte[] <--- I want the numbers in the Array
---->>>> as UnicodeString: M

Thx
PS: Please ignore the broken English - It's hard to discribe my problem..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top