Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2005-04-03
7
Medium Priority
?
185 Views
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.


Thomas
0
Comment
Question by:ThomasBurgin
4 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 13694245
so is this the ORIGINAL string:

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

and would the first suub-string then be

WIWMM,5.5,23,A,B,C

and the next substring would be:

GPRMC,111111.27,A,00000.10878,N,00000.10878,W,5.0,315,0,1

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

AW
0
 

Author Comment

by:ThomasBurgin
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

Thomas
0
 
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 ?

;-)
Shiju
0
 
LVL 3

Accepted Solution

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

The "potential input stream" could be:
     12345$WIWMM,5.5,23,A,B,C*??$GPRMC,111111.27,A,00000.10878,N,00000.10878,W,5.0,315,0,1*57236789
...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)
               Loop
          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 ! ! !
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

578 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