VS 2010 - create string from delimited byte list-VBForums
Results 1 to 5 of 5

Thread: VS 2010 - create string from delimited byte list

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2014
    Posts
    28

    VS 2010 - create string from delimited byte list

    The objective is to create a string from a list of byte format. The list consists of a series of short commands composed of 2-5 bytes and ending with a ";" character. The code should peal off the first command to the delimiter. Here's the code currently used:

    Code:
    dim SP2buf as new list(of byte)(2000)
    dim todo(1000) as char
    dim SP2idx as integer
    
     If SP2buf.Count > 0 Then
                    SP2idx = SP2buf.IndexOf(59)   'find the ; delimiter
                    If SP2idx >= 0 Then   ' is the ; there 
                        todo = (SP2.Encoding.GetChars(SP2buf.ToArray, 0, SP2idx))
                    End If
      End If
    Since the todo array gets converted to a string a bit later in the program, I want to just define it as a string to begin with and convert directly from the byte list to a string, but stopping the conversion when the delimiter is encountered. I haven't seen any VB capability to do that directly. Any help?

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,616

    Re: VS 2010 - create string from delimited byte list

    Convert the entire byte array to a string, then use string manipulators (split, substring, indexOf, etc) to get what you want.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2014
    Posts
    28

    Re: VS 2010 - create string from delimited byte list

    Quote Originally Posted by kebo View Post
    Convert the entire byte array to a string, then use string manipulators (split, substring, indexOf, etc) to get what you want.
    If you mean to convert the entire list to a string, that's probably not a good idea here as another thread is adding to the list and the list could be a couple of hundred bytes long depending on activity.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    31,120

    Re: VS 2010 - create string from delimited byte list

    So, you have a list that is constantly being added to, and there are preriodic ; as delimiters. You want to peal off items as they are available?

    I'd have the other thread doing all that. What's it doing otherwise? After all, it sounds like all you are creating is a queue of messages. Most likely, the other thread can build to some local list until a ; is found, at which point it can convert that local list to a string, add the string to a Queue(of String), raise an event on the UI thread (or whatever the first thread is) to inform it that there is something in the queue (which it can then deal with as it gets to it), then clears it's local List and starts building it again. That's not asking much of either thread and puts the processing where it will work best.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2014
    Posts
    28

    Re: VS 2010 - create string from delimited byte list

    That's not too far from the way it's designed. The first thread is reading a high speed serial port and the data is a string of requests and commands from a remote program. The thread builds a queue of those and this second thread removes a message from the queue, does the required processing and then waits for the first thread to signal that there's another message on the queue. At any point in time, there may be several messages in the queue waiting to be serviced. This is actually part of a larger system and there are a total of 7 threads (exclusive of UI thread) servicing 3 high speed ports. All of this works quite well and I'm just looking at eliminating some steps in handling the data.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.