Saturday, December 29, 2007

C#: Convert string to byte array

public byte[] ConvertStringToByteArray(string input)
{
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
return enc.GetBytes(input);
}

5 comments:

  1. Please I want to know whether we can covert String Array into Byte Array......
    For Example "3DFC" into 0x3D and 0xFC
    Plz mail me in naveencali@gmail.com
    Naveen

    ReplyDelete
  2. Use the Convert.ToBase64String() and Convert.FromBase64String()

    --
    Nhilesh Baua

    ReplyDelete
  3. Encoding.ASCII.GetBytes() works also.

    ReplyDelete
  4. Please I want to know whether we can covert String Array into Byte Array......
    For Example "3DFC" into 0x3D and 0xFC

    Please mail to my mail id adityamaroju@gmail.com
    please i require it urgently

    ReplyDelete
  5. is there any method like ConvertStringToByteArray() which converts string to byte array but doesnt take any argument.

    ReplyDelete

Please use your common sense before making a comment, and I truly appreciate your constructive criticisms.