Results 1 to 2 of 2

Thread: Retrieving actual length of a buffer array

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2003
    Location
    Seattle, WA
    Posts
    17

    Retrieving actual length of a buffer array

    Howdy,

    I've got an array with a fixed size ( Public Buffer(10000) As Byte )..How would I figure out how many characters are actually in it (.Length returns the size of the array).

    Intrestingly enough, If i convert it to a string:

    Dim str As String = System.Text.Encoding.ASCII.GetString(Buffer)

    str.Length also returns the size of the buffer array, so I guess another question would be how to get the number of characters in that string.

    Thanks in advance,
    FireRabbit

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    If you are sure that the data are added to your array consequetively then you can use the following code to retrive the actual lenght of it.
    VB Code:
    1. Dim Buffer(10000) as Byte
    2. '
    3. '
    4. '
    5.  
    6. Dim i as Integer ' the lenght you are looking for
    7. i=buffer.IndexOf(buffer, CByte(Nothing))
    8.  
    9. ' And for any string
    10.  
    11. i=str.Indexof(Nothing)
    but if the data is scatterred around in you buffer then i am affraid you have no other way than looping through the buffe and counting the empty bytes.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

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