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. Adding a string to an existing byte array

Adding a string to an existing byte array

Scheduled Pinned Locked Moved Visual Basic
tutorialcsharpc++data-structures
4 Posts 3 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.
  • S Offline
    S Offline
    Scott Barbour
    wrote on last edited by
    #1

    While I'm sure I could easily work out something to do this, I was wondering if there was a function that would add an array of bytes to the end of an existing byte array. Specifically, I am working on a project where a method takes a byte array as a parameter, where the byte array contains more than just a converted string. Original C/C++ sample code:

    unsigned char buf[10];
    int len = 10;

    buf[0] = 9;
    buf[1] = 76;
    sprintf((char*)&buf[2], "%d", groupnum);

    I'm sure the answer is obvious, but it's just not hitting me in the face right at the moment. :~ (For those interested, this is an example from Avaya's "IP Office TAPI Link Developer's Guide" to build the parameter block for the lineDevSpecific function of TAPI 2.x. I'm working on the project in VB.NET using JulMar's ATAPI.NET wrapper. I'm having another issue with the function call to use the byte array, but that's another matter entirely.)

    D G 2 Replies Last reply
    0
    • S Scott Barbour

      While I'm sure I could easily work out something to do this, I was wondering if there was a function that would add an array of bytes to the end of an existing byte array. Specifically, I am working on a project where a method takes a byte array as a parameter, where the byte array contains more than just a converted string. Original C/C++ sample code:

      unsigned char buf[10];
      int len = 10;

      buf[0] = 9;
      buf[1] = 76;
      sprintf((char*)&buf[2], "%d", groupnum);

      I'm sure the answer is obvious, but it's just not hitting me in the face right at the moment. :~ (For those interested, this is an example from Avaya's "IP Office TAPI Link Developer's Guide" to build the parameter block for the lineDevSpecific function of TAPI 2.x. I'm working on the project in VB.NET using JulMar's ATAPI.NET wrapper. I'm having another issue with the function call to use the byte array, but that's another matter entirely.)

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      I have no idea what you're getting at,but you may want to look into the System.Text.StringBuilder class.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      1 Reply Last reply
      0
      • S Scott Barbour

        While I'm sure I could easily work out something to do this, I was wondering if there was a function that would add an array of bytes to the end of an existing byte array. Specifically, I am working on a project where a method takes a byte array as a parameter, where the byte array contains more than just a converted string. Original C/C++ sample code:

        unsigned char buf[10];
        int len = 10;

        buf[0] = 9;
        buf[1] = 76;
        sprintf((char*)&buf[2], "%d", groupnum);

        I'm sure the answer is obvious, but it's just not hitting me in the face right at the moment. :~ (For those interested, this is an example from Avaya's "IP Office TAPI Link Developer's Guide" to build the parameter block for the lineDevSpecific function of TAPI 2.x. I'm working on the project in VB.NET using JulMar's ATAPI.NET wrapper. I'm having another issue with the function call to use the byte array, but that's another matter entirely.)

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

        Use the Array.Copy or Array.CopyTo method to copy the data from one array into another array. Use the Encoding.GetBytes method to encode a string into a byte array. Example: byte[] group = Encoding.UTF8.GetBytes(groupNumber.ToString());

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

        S 1 Reply Last reply
        0
        • G Guffa

          Use the Array.Copy or Array.CopyTo method to copy the data from one array into another array. Use the Encoding.GetBytes method to encode a string into a byte array. Example: byte[] group = Encoding.UTF8.GetBytes(groupNumber.ToString());

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

          S Offline
          S Offline
          Scott Barbour
          wrote on last edited by
          #4

          Array.CopyTo is exactly what I was looking for. :)

          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