Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to convert one byte to string?

How to convert one byte to string?

Scheduled Pinned Locked Moved C#
tutorialdata-structureshelpquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nhatvhm
    wrote on last edited by
    #1

    In MSDN guide convert array bytes to string, here code: Encoding.UTF8.GetString(byte[] bytes)VS2005 doesn't support convert one byte to string. Anybody can I help me? or for example how to convert one byte to string. Although, may be use to Convert.ToString(byte) is correct, but I don't think so. Except, differently another way Thank one so much!!!!

    P L G 3 Replies Last reply
    0
    • N nhatvhm

      In MSDN guide convert array bytes to string, here code: Encoding.UTF8.GetString(byte[] bytes)VS2005 doesn't support convert one byte to string. Anybody can I help me? or for example how to convert one byte to string. Although, may be use to Convert.ToString(byte) is correct, but I don't think so. Except, differently another way Thank one so much!!!!

      P Offline
      P Offline
      prasadbuddhika
      wrote on last edited by
      #2

      Encoding.UTF8.GetString(byte[] bytes) is working. did you try the method Tostring();

      1 Reply Last reply
      0
      • N nhatvhm

        In MSDN guide convert array bytes to string, here code: Encoding.UTF8.GetString(byte[] bytes)VS2005 doesn't support convert one byte to string. Anybody can I help me? or for example how to convert one byte to string. Although, may be use to Convert.ToString(byte) is correct, but I don't think so. Except, differently another way Thank one so much!!!!

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Just make a byte array with only this byte in it. GetString(new byte[] { myByte }); regards

        1 Reply Last reply
        0
        • N nhatvhm

          In MSDN guide convert array bytes to string, here code: Encoding.UTF8.GetString(byte[] bytes)VS2005 doesn't support convert one byte to string. Anybody can I help me? or for example how to convert one byte to string. Although, may be use to Convert.ToString(byte) is correct, but I don't think so. Except, differently another way Thank one so much!!!!

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          If you encode a single character into bytes using the UTF-8 encoding, it can result in more than a single byte. It wouldn't make sense to have a method that decodes a single byte, as that would only work on a very limited part of the character set. If you have a character that actually was encoded into a single byte, you just have to put that byte in an array to decode it. If you are trying to decode data byte by byte, that doesn't work, as some characters may need more than one byte of the data.

          Despite everything, the person most likely to be fooling you next is yourself.

          D 1 Reply Last reply
          0
          • G Guffa

            If you encode a single character into bytes using the UTF-8 encoding, it can result in more than a single byte. It wouldn't make sense to have a method that decodes a single byte, as that would only work on a very limited part of the character set. If you have a character that actually was encoded into a single byte, you just have to put that byte in an array to decode it. If you are trying to decode data byte by byte, that doesn't work, as some characters may need more than one byte of the data.

            Despite everything, the person most likely to be fooling you next is yourself.

            D Offline
            D Offline
            Daniel Grunwald
            wrote on last edited by
            #5

            Guffa wrote:

            If you have a character that actually was encoded into a single byte, you just have to put that byte in an array to decode it.

            If you have a character that was encoded into a single byte using UTF8, then it was an ASCII character. Instead of allocating lots of small byte arrays, you can just do this:

            char DecodeASCII(byte b)
            {
            if (b >= 128)
            throw new ArgumentException("This is not a single-byte character");
            else
            return (char)b;
            }

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups