Results 1 to 6 of 6

Thread: From byte[] to string or char[]?

  1. #1

    Thread Starter
    Lively Member neodatatype's Avatar
    Join Date
    Aug 2002
    Location
    Italy
    Posts
    103

    Question From byte[] to string or char[]?

    How can I do to convert a byte[] array into a char[] array or a string avoiding loops for each byte?

    Thank you!
    > NeoDataType.net <

    Try my Free .Net Reporting Tool!

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    I'm not sure but try Convert.ToCharArr();
    Dont gain the world and lose your soul

  3. #3

    Thread Starter
    Lively Member neodatatype's Avatar
    Join Date
    Aug 2002
    Location
    Italy
    Posts
    103

    Angry

    I'm not sure but try Convert.ToCharArr();
    Yessss, if that would exist...

    But... what's the aim of your replay?
    > NeoDataType.net <

    Try my Free .Net Reporting Tool!

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Ok bro, I dont know about the char[], but if you want to convert a byte[] to string, you can try this Convert.ToBase64String().

    BTW the aim of my reply was to try and help you. Calm down and go have a cup of coffee man.
    Dont gain the world and lose your soul

  5. #5
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327

    Talking byte conversion

    copied from MSDN byte conversion topic:

    Code:
    ASCIIEncoding AE = new ASCIIEncoding();
    byte[] ByteArray = { 69, 110, 99, 111, 100, 105, 110, 103, 32, 83, 116, 114, 105, 110, 103, 46 };
    char[] CharArray = AE.GetChars(ByteArray);
    for(int x = 0;x <= CharArray.Length - 1; x++)
    {
       Console.Write(CharArray[x]);
    }
    -scott
    he he he

  6. #6
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    Code:
    private byte[] StrToBytes(string  s)
    {
    	return System.Text.Encoding.ASCII.GetBytes(s);
    }
    take a look at System.Text.Encoding.ASCII -- if memory serves you can probaby GetChars() too.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width