Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Ok here is what I am trying to do first the contents of the string

 

I have an array that has forty or more of the following each element of the array contains data like this I need to parse

 

Name: Lanton Lamho Race: White Sex: Male Age: 18 DOB: 05-10-90 Height: 5�06 Weight: 152 Hair: Blk Eyes: Brown TPD#Lanton Lamho broke into the Quickie Mart located at 5310 S. Peoria Ave. The suspect used a manhole cover to throw...

 

NOTE!!!!!! Some of the names are first middle last not just first and last

 

Anyway I need

 

I need descriptions in labels and info in other labels

 

like this

 

Name: John Smith

Race: White

Sex: Male

Age: 25

ect ect until it gets to the TPD# I need that stripped and all following put into a label of its own

 

ie; Guy did what ever he did and he is in trouble for it LOL

 

anyway .... I tried a multiple delimiter spit but the results left empty elements of the array ....

 

Anyone got some ideas how I might best parse this?

 

Heres the code I used and tried to modify but it wont work exactly right

 


Dim values As String

       values = "Name: John Smith Race: White DOB: 1/22/60"

       Dim sites As String() = Nothing

       Dim sep(3) As Char

       sep(0) = ": "

       sep(1) = " Race:"

       sep(2) = " DOB:"

       sites = values.Split(sep, 9)

       Dim s As String

       For Each s In sites
           rtb1.Text = rtb1.Text & s.Trim(" ") & vbCrLf

       Next s

 

Help much appreciated

 

Mark

Visual Basic 2008 Express Edition!
Posted (edited)

Ok I have made some headway but still not there yet .... I am now getting a clean split but I realize something that I am not sure what to do with

Obviously I am wanting to take the string as seen in this partial example of the string

 

Example string

Dim exampString as String

 

exampString = "Name: John Smith Race: White" ect ect ect ect

 

My code is now returning this

 

Name

John

Smith

Race

White ................. continues till it gets to TPD# then does this

TPD# summary text ......

 

 

 

 

and so on .... but the problem is not in the co as much as it is the strings it will be parsing

most ar as above but a few will have a middle name to like

 

Dim exampString As String

exampString = "Name: Mary Jane Smith Race: White Sex: Female"

 

and so on .......

 

If they didnt have the middle name my problem would be solved but the it is

 

I may be going about this still all wrong though as what I am wanting to do is put it back together in an order like this

 

Name: John Smith or John William Smith should a middle name exist

Race: White

Sex: Male

Age: 45 continuing this on down to

TPD# summary text ......

 

like that perhaps you guys could you point a better direction o what I might be overlooking

 

all help is much appreciated

 

vbMarkO

ooops forgot to ad the code here it is

 
       Dim values As String

       values = "Name: Lanton Lamho Race: White Sex: Male Age: 18 DOB: 05-10-90 Height: 5’06 Weight: 152 Hair: Blk Eyes: Brown TPD#Lanton Lamho broke into the Quickie Mart located at 5310 S. Peoria Ave. The suspect used a manhole cover to throw..."

       Dim myString As String() = Nothing

       Dim sep(3) As Char

       sep(0) = ": "

       sep(1) = " Race:"

       sep(2) = " DOB:"

       myString = values.Split(sep, 29)

       Dim s As String
       Dim sArr As New ArrayList

       For Each s In myString
           sArr.Add(s).ToString.Replace(" ", ",")



       Next s
       For i = 0 To sArr.Count - 1
           If sArr(i) = "" Then

           Else
               rtb1.Text = rtb1.Text & sArr(i).ToString.Trim(" ") & vbCrLf
           End If
       Next

Edited by vbMarkO
Visual Basic 2008 Express Edition!
  • *Experts*
Posted

Here's something that works, assuming you take out all the parts after the "TPD#". This is not really the proper way to do this... you should be using regular expressions. I tried to do that, but I couldn't figure it out at the moment.

 

To solve your problem, you need to treat your string more generally; don't hard-code what each "label" is (name, DOB, etc.). Instead, just look for words that end in ":" and break lines up according to that.

 

       Dim values As String
       values = "Name: Lanton Lamho Race: White Sex: Male Age: 18 DOB: 05-10-90 Height: 5�06 Weight: 152 Hair: Blk Eyes: Brown"

       Dim words As String() = values.Split(New Char() {" "c}) ' Split input string into words
       Dim lastLabel As Integer = -1 ' Keep track of the previous label's location in the array

       Dim output As String = ""

       For i As Integer = 0 To words.Length - 1
           Dim word As String = words(i)
           If word.EndsWith(":") Then ' If we have a label (ends with ":") ...
               If lastLabel <> -1 Then ' ... and we know where the last label was...
                   For j As Integer = lastLabel To i - 1 ' ... then concatenate all the words between the labels
                       output &= words(j) & " "
                   Next
                   output &= Environment.NewLine
               End If

               lastLabel = i ' Bump up the location of the label
           End If
       Next

       ' Your string will be in the variable output

 

Hope this helps.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...