CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Location
    Fort Worth Texas
    Posts
    614

    Question Encoding problem

    The following simple code does not work(sY is empty). Does anyone have an idea why. This is using .NET 1.1

    Encoding u8 = Encoding.UTF8;
    string sX = "\x92"; // WORKS!
    byte[] byteOne = new byte[1];
    byteOne[0] = (byte)146;
    string sY = u8.GetString(byteOne); // NOIE WORKIE!

    sX works fine because it has the hex value in the string, but sY converting from the byte array doesn't (it's empty).

  2. #2
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074

    Re: Encoding problem

    Just read MSDN, always a good idea...
    UTF-8 encodes Unicode characters with a variable number of bytes per character.
    Code:
    string sX = "\x92"; // WORKS!
    byte[] sxBytes = u8.GetBytes(sX); // byte[0] = 194 byte[1] = 146
    sX == u8.GetString(sxBytes)
    Useful? Then click on (Rate This Post) at the top of this post.

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