C# .NET - Type conversion

Asked By mostafa hamdy on 21-Sep-06 06:53 AM

Hi all

I want to convert string variable to byte[] array , plz can any body tell me how can I do that?

regards

Mostafa

Shallu Gupta replied to mostafa hamdy on 21-Sep-06 07:23 AM
 System.Text.ASCIIEncoding  encoding=new System.Text.ASCIIEncoding();
    encoding.GetBytes(str);

Converting strings to bytes and vice versa

K Pravin Kumar Reddy replied to mostafa hamdy on 21-Sep-06 07:26 AM

hello

In C#, use System.Text.Encoding, which has identical behaviour to the function in VB.NET.

byte[] abData;
string Str;
int i;
Str = "Hello world!";
// Convert string to bytes
abData = System.Text.Encoding.Default.GetBytes(Str);
for (i = 0; i < abData.Length; i++)
{
	Console.WriteLine("{0:X}", abData[i]);
}
// Convert bytes to string
Str = System.Text.Encoding.Default.GetString(abData);
Console.WriteLine("'{0}'", Str);
reference for vb.net vb6 vba and more
http://cryptosys.net/cgi-bin/manual.cgi?m=pki&name=stringstobytes