Results 1 to 5 of 5

Thread: string to byte array "åäöÿ" is "????"

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    3

    Question string to byte array "åäöÿ" is "????"

    Hi
    I have a question about byte arrays.

    This is the line where it be wrong.

    CODE]
    Dim MyByte() As Byte = Encoding.ASCII.GetBytes(sString)
    [/CODE]

    if I have a ÿ in "sString" then it change it to ? it´s the same with åäö.

    Do anybody now how to fix it!

    plz
    Tankz m00gly
    Why search and search when you can ask.

  2. #2
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261

    Re: string to byte array "åäöÿ" is "????"

    Originally posted by m00gly
    Hi
    I have a question about byte arrays.

    This is the line where it be wrong.

    CODE]
    Dim MyByte() As Byte = Encoding.ASCII.GetBytes(sString)
    [/CODE]

    if I have a ÿ in "sString" then it change it to ? it´s the same with åäö.

    Do anybody now how to fix it!

    plz
    Tankz m00gly

    Hmm, I remember having this problem as well! I think it has something to do with the fact that Strings in .NET use the unicode character set (each character is two bytes, not one).

    I'll go find a work around!

  3. #3
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Yep, .NET utilizes the unicode character set. You can use the UnicodeEncoding class for all unicode manipulation:

    Code:
        byte[] bytes = new System.Text.UnicodeEncoding().GetBytes(value);

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    3

    Unhappy thanks but i´ve didn´t get it to work

    Hmm it didn´t work for me, my function looks like this

    Code:
     
    Public Function SendText(ByVal sValue As String, ByVal sRemoteHost As String)
    Dim MyByte As Byte()
     
            MyByte = New System.Text.UnicodeEncoding().GetBytes(sValue)
    
            MySocket.Send(MyByte, MyByte.Length, sRemoteHost)
    
        End Function
    With this code "ÿ" will be a "square" and "å" will be "e"
    Why search and search when you can ask.

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    3

    Talking Sorry my mistake?

    I hav forgot to change to unicode in the recive function!

    Tanks for all help
    Why search and search when you can ask.

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