CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2005
    Posts
    298

    Question string to byte[]

    how do I do string to byte[]?

    there is
    Encoding.ASCII.GetBytes
    Convert.FromBase64String
    BitConverter
    Encoding.UTF8
    UnicodeEncoding

    etc

    I don't understand all the diff.

    AFAIK the input will be not limited to ascii. It will have eg Japanese input from a J WinXP.

    Also, what is the big/little endian deal? I thought .net frame should deal with those details??



  2. #2
    Andy Tacker is offline More than "Just Another Member"
    Join Date
    Jun 2001
    Location
    55°50' N 37°39' E
    Posts
    1,503

    Re: string to byte[]

    you can use... the one...

    Encoding.default.getbytes() function.
    If you think you CAN, you can, If you think you CAN'T, you are probably right.

    Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.

  3. #3
    Join Date
    Apr 2005
    Posts
    298

    Re: string to byte[]

    how about dealing with Japanese input from a J WinXP.
    then reading the same on Eng WinXP?

    This endian thing is also worrying, one day someone's going to run .net on some wierd processor and everything will explode??!

  4. #4
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: string to byte[]

    If you're doing the conversion using Unicode then you'll be fine.

    However if you're doing it to ASCII you'll have to set up the codepage :

    Code:
    string sString = "<some japanese>";
    
    // get the encoding specifying a code page.
    Encoding asciiJapanese = System.Text.ASCIIEncoding.GetEncoding(932);
    byte [] abData = ascciiJapanese.GetBytes(sString);
    932 is the code page for Japanese.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

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

Featured