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. Visual Basic
  4. Convert a string into byte array

Convert a string into byte array

Scheduled Pinned Locked Moved Visual Basic
data-structurestutorialquestion
5 Posts 3 Posters 1 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.
  • W Offline
    W Offline
    Will8888888
    wrote on last edited by
    #1

    Could somebody tell me how to convert a string (0 to 255 range) to a byte array?

    William

    G A 2 Replies Last reply
    0
    • W Will8888888

      Could somebody tell me how to convert a string (0 to 255 range) to a byte array?

      William

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

      Use the encoding of your choise and the GetBytes method: messageArray = Encoding.ASCII.GetBytes("Hello world")

      --- b { font-weight: normal; }

      W 1 Reply Last reply
      0
      • G Guffa

        Use the encoding of your choise and the GetBytes method: messageArray = Encoding.ASCII.GetBytes("Hello world")

        --- b { font-weight: normal; }

        W Offline
        W Offline
        Will8888888
        wrote on last edited by
        #3

        Hi, Thank you very much for help. Your code just works for ASCII characters. What about the characters in the range from 0 to 255?? Thank you again, William

        William

        G 1 Reply Last reply
        0
        • W Will8888888

          Hi, Thank you very much for help. Your code just works for ASCII characters. What about the characters in the range from 0 to 255?? Thank you again, William

          William

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

          That's why I said that you should choose an encoding. Use the encoding that was used to create the string.

          --- b { font-weight: normal; }

          1 Reply Last reply
          0
          • W Will8888888

            Could somebody tell me how to convert a string (0 to 255 range) to a byte array?

            William

            A Offline
            A Offline
            AlexeiXX3
            wrote on last edited by
            #5

            Dim textConverter As New System.Text.UTF8Encoding Dim bytes() As Byte = textConverter.GetBytes("Text to convert")

            Alexei Rodriguez

            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