Bread a Long string in sub string that have known starting and ending strings.

Posted on 2005-04-03
Medium Priority
Last Modified: 2013-12-26
I am reading  text data from a serial port.  The long text has several sub data strings.  At time the first few characters are not apart  of the sub data string.  The first part of each sub data string starts with a $ and ends with sum check or *66.  I need to remove each of the sub strings and read them into an array.  

First problem is that trash data must be removed from the start of the long string and from the end.  I do not find a funtion that will remove these trash or remove those characters.

Second I do not know how to remove the four or five sub string that are in the long serial port string.  The long string may look like this "12345$WIWMM,5.5,23,A,B,C*$GPRMC,111111.27,A,00000.10878,N,00000.10878,W,5.0,315,0,1*57236789"
Once the Sub string are read I can read the data on the sub string, but I con not know how to remove and read each sub string.

Visual Basic .Net is being used and it does not allow sum VB6  function.

Question by:ThomasBurgin
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 44

Expert Comment

ID: 13694245
so is this the ORIGINAL string:


and would the first suub-string then be


and the next substring would be:


Is that correct so far.

Or could you give examples of what you mean by 'garbage' string, and the substrings that you expect from this original string


Author Comment

ID: 13694507
The garbage would be 12345 of the long string and the garbage would be 236789 on the end.  The *57 is the check sum.  A check sum should be before the $GPRMC of the second sub string.  I forgot to put in in  The check sum would be *?? at the end of each sum string

LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 13694923
hi ThomasBurgin
 that means in a given string ur meaning ful data starts with

  $ symbol and ends with *??
   where ? is any digit
and u need a function to extract this ?
  is this right ?


Accepted Solution

JigglyD earned 2000 total points
ID: 13695466
Okay, let's see if I have this straight...

The "potential input stream" could be:
...and you are positive that each sub-string will be prefixed with $, and suffixed with *??

Well, to abate your initial concerns, the .NET platform will support many of the VB6 functions you have come to know and love.  For example, Microsoft.VisualBasic.Right(SourceString, 5) will return the five rightmost characters... just like in VB6.  Many others exist... just type in Microsoft.VisualBasic.   and watch the context sensitive menu spring to life.

Now, regarding your parsing problem, try this...
     Dim ResultArray() As String
     Dim Bucket As String

     Bucket = "12345$WIWMM,5.5,23,A,B,C*??$GPRMC,111111.27,A,00000.10878,N,00000.10878,W,5.0,315,0,1*57236789"

     If InStr(Bucket, "$") Then
          Bucket = Mid(Bucket, InStr(Bucket, "$") + 1)  '*** Remove prefixed garbage, and the leading $
         '*** Remove the suffixed garbage
          If Len(Bucket) >= 4 Then
               Do While Mid(Bucket, Len(Bucket) - 3) <> "*"
                    Bucket = Mid(Bucket, 1, Len(Bucket) - 1)
          End If
         '*** Establish you result array
          ResultArray = Split(Bucket, "$")
     End If

Now you will be left with a string array of each of your sub-string (without the leading dollar signs)... and each array value will still contain your checksum value.

Jiggle On ! ! !

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question