Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for strings within your strings...

Status
Not open for further replies.

VBBro

Programmer
Jun 25, 2004
4
0
0
US
I am trying to write a program using Visual Basic.Net / 6.0 that will search through a very long piece of text pasted into a text-box.

Inside the text-box are patterns of numbers like this, representing a file number

12345-123456
12345-123456-1234
1234

and patterns of numbers with letters like this, representing the location code

01R05AA02F

The above represents one occurrence of possibly hundreds in a single document. Between the file number and the location code is extraneous information that needs to be separated from the file number and the location code.

My approach at first was to delete the extraneous information from the text-box. After some time of debatable progress, I decided to try the opposite – pull the desired information into a new text-box. Getting hung up here also.

I have been trying various string manipulations, Find, Like, Instr, IndexOf, etc… I feel like I am on the right track but my Monday morning deadline is rapidly approaching and stress has begun to surface.

I was hoping someone may be able to lend me some wisdom, please.
 
Ok let me make sure I have the issue straight.

You have:

123456-123456bunchofuselessjunk01R05AA02F

You want:

123456-123456 'As a variable
01R05AA02F 'As a variable

Is this correct?

1) Is the location code always 10 digits?
2) What are the variations in the file-number length?

Matt

 
Instr - Determines if one string is found within a second string


BIsFound = Instr(1, String1, String2)
 
Sounds like a case for using the VB Regular Expression component. The RegExp component provides PERL like regular expression matching and gives you the ability to extract the matched strings.

If you've never used Regular Expressions it's a pretty steep learning curve at first but well worth the effort.
Look it up in MSDN and work through a few simple examples.

Actually your requirement sounds pretty easy to do in RexExp terms so you may find that you can achieve what you want quite quickly.

 
Sorry I didn't read all of your post.

Like MattSTech is asking, I would need to know if each string segment you need is a certain length. If it is, loop through the string segments and sort them into an array.

If you know the size of the file number and the size of the location number are always the same, you can easily sort them out.
 
I finally produced a working copy of the .NET program I have been working on but when I copy the .exe to another computer using Win 2000, it says, "Not a Valid Win32 App"....

Apparently, I just learned the hard way that VB.NET requires the .NET framework to run.

Anyway, I had to rewrite the entire program using VB6.0 and thanks to the help of the goodly people of Xtreme VB Chat, it is finished and functional! Thanks! Here is a sample of the text I was trying to extract from and the code I used.

10124-000088 WYATT, INC. || CHIEF CONSTRUCTION COMPANY
10124-000088-0001
0001 TAX ASSESSMENT APPEAL 01R05AA02F 09/05/03 10/24/03 07/08/03 ____ ____ ____ |____

Dim myString As String
myString = textbox1.Text
Dim myArray() As String
myArray = Split(myString)
Dim a, i As Long
a = UBound(myArray)
textbox1.Text = ""
For i = 0 To a

If myArray(i) Like "*?######" Then
textbox1.Text = textbox1.Text & Chr$(13) & Chr$(10) & _
myArray(i) & Chr$(13) & Chr$(10)
i = i + 1

ElseIf myArray(i) Like "#####?######?####" Then
textbox1.Text = textbox1.Text & myArray(i) & Chr$(13) & Chr$(10)
i = i + 1

ElseIf myArray(i) Like "####" Then
textbox1.Text = textbox1.Text & myArray(i) & Chr$(13) & Chr$(10)
i = i + 1

ElseIf myArray(i) Like "##[!/]##??##?" Then
textbox1.Text = textbox1.Text & myArray(i) & Chr$(13) & Chr$(10)

End If
Next i
Dim txt As String
txt = textbox1.Text
txt = Replace(txt, "|____", "")
txt = Replace(txt, "Pulled", "")
txt = Replace(txt, "-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", "")
textbox1.Text = txt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top