|
-
Feb 16th, 2007, 07:28 PM
#1
Thread Starter
Fanatic Member
Search String
Is there API or a Refrence in VB that will allow me to quickly(as in 1 or 2 lines of code) check a string to see if another string is in it?
Example:
Im searching through these 4 lines:
aaaaaaaaaaaaaaaaa1aaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaa111aaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1
My search string is "11"
It will return the 3rd line only, since it contains my search string.
Ive seen it before but i cant find it anywhere, it was 1 line of code that would return true or false.. Thats what i need
Any help would be greatly appreciated, thank you!
-
Feb 16th, 2007, 07:38 PM
#2
Lively Member
Re: Search String
VB Code:
InStr(<start position>, <string>, <comparison>)
this will return an integer value to show where the string is.
-
Feb 16th, 2007, 07:39 PM
#3
Re: Search String
Do you need to determine if string containg the search string ONLY or you need to return entire line containing the search string?
Sorry but I'm lost...
-
Feb 18th, 2007, 03:41 AM
#4
Re: Search String
 Originally Posted by PMad
Is there API or a Refrence in VB that will allow me to quickly(as in 1 or 2 lines of code) check a string to see if another string is in it?
Example:
Im searching through these 4 lines:
aaaaaaaaaaaaaaaaa1aaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaa111aaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1
My search string is "11"
It will return the 3rd line only, since it contains my search string.
Ive seen it before but i cant find it anywhere, it was 1 line of code that would return true or false.. Thats what i need
Any help would be greatly appreciated, thank you!
The text was probably in a richtextbox
VB Code:
Dim lngPos As Long
lngPos = InStr(1, RTB.Text, "11")
If lngPos > 0 Then
MsgBox "Line " & (RTB.GetLineFromChar(lngPos) +1) 'note, 1st line is line index 0 so adjust by 1
Else
MsgBox "Not found"
End If
-
Feb 20th, 2007, 12:11 PM
#5
Thread Starter
Fanatic Member
Re: Search String
Sorry for such a late reply on this, but let me explain.
Ive got a file that has some headers in it for a user, then its got the rest of the file information in it.
There's a form that will load, and it will read the header information for every file in a subdirectory in the applications path, and display certain portions of the information on a ListView.
Above the ListView box there's a series of text boxes, each are for searching through the list of files that came up. You can search by first name, last name, address, phone number, company name, company phone number, company address, the unique ID number, all kinds of things, and it will search through each field.
Well, this directory will have over 1000 files in it within the next year, so each time i search, it may take some time for each search, but im trying to find the most efficient way to do this so it will be the fastest.
So for example, if you search the first name field for "ri", then it will return every entry that contains the letters "ri" anywhere in the first name.
Right now, i go through a couple of For~Next loops. First one to count the rows, 2nd one inside the first that goes the len(firstnamefield) and uses mid$ to scan through each one.. But this method can be fairly slow, not certain if there's a faster way, but it really seems like there should be.
I hope this clarified everything better, thank you for the help so far everybody
-
Feb 20th, 2007, 03:01 PM
#6
Re: Search String
Maintain a database file (an .mdb file would be the easiest - you can create it and maintain it in your code) that has one record per file in the directory, with one field for each item in the header, and one field with the file name. Then a simple SQL Select statement well give you all the files for the search condition, and it'll be fast.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Feb 20th, 2007, 07:20 PM
#7
Re: Search String
With an external DB, you'll have to sync the database...
You can wrap up your file operations into a class that does what you just described for each file. Iterate through the directory and create a new instance (store classes in a collection) for each file, just pass the path to the class. Class exposes header, search results, etc as properties/methods. File open/close is done internally in the class.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|