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. Adding 2 Zeros after each byte in textbox

Adding 2 Zeros after each byte in textbox

Scheduled Pinned Locked Moved C#
tutorialquestion
6 Posts 4 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.
  • X Offline
    X Offline
    xEvOx
    wrote on last edited by
    #1

    ok i really hounestly (on my own mind and heart) cant think of ANY code to start this, right so a value in a textbox say equals "999" i want to then convert it to hex (i know how to do that with SB) then having it add 1 byte (00) after each byte so : "3900390039" how would i go about doing this ? Thanks

    R L R 3 Replies Last reply
    0
    • X xEvOx

      ok i really hounestly (on my own mind and heart) cant think of ANY code to start this, right so a value in a textbox say equals "999" i want to then convert it to hex (i know how to do that with SB) then having it add 1 byte (00) after each byte so : "3900390039" how would i go about doing this ? Thanks

      R Offline
      R Offline
      Rob Philpott
      wrote on last edited by
      #2

      Is this an attempt at UTF-16? Why not iterate over the 999, converting one character at a time and adding the '00'?

      Regards, Rob Philpott.

      1 Reply Last reply
      0
      • X xEvOx

        ok i really hounestly (on my own mind and heart) cant think of ANY code to start this, right so a value in a textbox say equals "999" i want to then convert it to hex (i know how to do that with SB) then having it add 1 byte (00) after each byte so : "3900390039" how would i go about doing this ? Thanks

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

        Try this:

        string s1 = "999";
        byte[] b1 = new byte[s1.Length * 2];
        int index = 0;
        foreach (char ch in s1)
        {
        b1[index++] = (byte)ch;
        b1[index++] = 0;
        }

        txtspeak is the realm of 9 year old children, not developers. Christian Graus

        R 1 Reply Last reply
        0
        • X xEvOx

          ok i really hounestly (on my own mind and heart) cant think of ANY code to start this, right so a value in a textbox say equals "999" i want to then convert it to hex (i know how to do that with SB) then having it add 1 byte (00) after each byte so : "3900390039" how would i go about doing this ? Thanks

          R Offline
          R Offline
          Rajesh Anuhya
          wrote on last edited by
          #4

          OK.., I giving u a idea about this.., read text box value to a byte array...,

          byte[] mybyte = Encoding.UTF8.GetBytes(textbox1.Text);

          declaring 0x00 byte

          byte x = 0x00;

          declare a new byte array and add, bytes as per your requirement. Tnanks

          Rajesh B --> A Poor Workman Blames His Tools <--

          L 1 Reply Last reply
          0
          • L Lost User

            Try this:

            string s1 = "999";
            byte[] b1 = new byte[s1.Length * 2];
            int index = 0;
            foreach (char ch in s1)
            {
            b1[index++] = (byte)ch;
            b1[index++] = 0;
            }

            txtspeak is the realm of 9 year old children, not developers. Christian Graus

            R Offline
            R Offline
            Rajesh Anuhya
            wrote on last edited by
            #5

            :thumbsup::thumbsup::thumbsup:

            Rajesh B --> A Poor Workman Blames His Tools <--

            1 Reply Last reply
            0
            • R Rajesh Anuhya

              OK.., I giving u a idea about this.., read text box value to a byte array...,

              byte[] mybyte = Encoding.UTF8.GetBytes(textbox1.Text);

              declaring 0x00 byte

              byte x = 0x00;

              declare a new byte array and add, bytes as per your requirement. Tnanks

              Rajesh B --> A Poor Workman Blames His Tools <--

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

              Huh? What's the idea here? Adding '\0' chars instead of '0' chars? Why a variable just to hold a constant 0?

              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