Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Searching For String In Text File


I am stuck again. I've searched the forum the all that I can and I am still stuck.


I have a program setup so that all the strings in lstConsole writes to a text file. I was wondering if you can tell me if it is possible to search that text file for a specific string, and if that string is there do this

not code

If text.txt has string "i shot the sheriff" then
lstconsole = "but i did not shoot the deputy"

I will be grateful for any help you can give me, and if its not to much trouble please explain it to me like I'm a 5yo.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Searching A Text File For A String
Hi,

What is the quickest way to find out if a text file contains a specified string?

I have a program that adds a string into HTML files. I do not want to add the string if it already exists in the file. I am processing upto 50 files at a go. (I am reading the file line by line until I find the right spot for the string.) Is it possible to read in the whole file in one go into one string and then do an instr command?...or something.

Thanks for any advice.

Searching And Deleteing String In Text File
i am useing this code to delete a line # in a text file:

Open "C:windowssystempersonnel.txt" For Input As #1
Open "C:windowssystempersonnel1.txt" For Append As #2
Do While Not EOF(1)
Input #1, LineStr
Line = Line + 1
If (Line <> linedel + 1) And (Line <> linedel) Then

Write #2, LineStr
Else
'Ignore the line
End If

Loop

Close #2
Close #1

Kill "c:windowssystempersonnel.txt"
Name "C:windowssystempersonnel1.txt" As "C:windowssystempersonnel.txt"
my question is i have alot of chkboxes in array and is it possible to delete a text line by searching for the words that you want to delete instede of the line number?

Searching For A String In A Text File Line By Line
eiSecure: The following code will work with single instances of the ~BEGIN and ~END tags, but it doesn't work with multiple instances (but you should be able to add it in if you play around with it for a bit).

VB Code:
Dim sFile As StringDim saFile() As StringDim strText As String Open "MyFile.txt" For Input As #1sFile = Input(LOF(1), 1)Close #1 saFile = Split(sFile, vbCrLf) For y = 0 To UBound(saFile)    If Trim$(saFile(y)) = "~BEGIN" Then        For x = y To UBound(saFile)            If Trim$(saFile(x)) = "~END" Then                For Z = y + 1 To x - 1                    strText = strText & saFile(Z) & vbCrLf                Next Z                strText = strText & vbCrLf            End If        Next x    End IfNext y Text1 = strText

Searching For A Directory Vs Searching A Text File For The Same Thing!
After working on a piece of code for a while, and actually getting it to work, I was asked to do it a different way.

Originally, I had a login box set up to search for a user's username and password that was stored in a text file. The problem with this was that I didn't know how to get it to search ALL of the entries, not just a set 1 to 10 like I was using in my code. To see the full program code, click here.

Now my group members want me to do it so that it searches for the directory instead of the text file for the same information. The directory name is the username, and in the directory, they'd like (theoretically speaking) to have the user's username and pass stored in a pwd file or a txt file.

I'm trying to argue that searching a text file's easier (partly because I believe it is, and also because I've already done it), but they're arguing that searching the directory's easier because then, the program could just store the directory in a global module, so when it comes to other aspects of the program itself, it'd be easier to do.

I'm willing to give the 'searching for the directory' route a try, but I can't seem to find anything that pertains to this, WITHOUT using api (I've searched the forum, and all I found was recursive search for stuff thats already in a directory, or stuff that has to do with api).

Any help would be greatly appreciated.

Searching A String Of Text
How do I search a string of text to see if another string is in it.

For example, the long string would be...."Hello World." and I want to know if "Hello" exists there. I'm sure this is easy and I should know this, but I can't figure it out. Thanks

Jacob Sheehy
http://www.sheehy.ca

Multitasking - screwing up several things at once

Searching For Text In A String
Hi

I just want to search for the string "AM" in rs("Duration"). I'm trying to do it like this but getting an error. Could someone help out

If InStr(0, (rs("Duration")), "AM") Then
MsgBox("Found")
End If


Thanks

Searching For A String In Text
How do you search for a string in a chunk of text? It's something like the "Find" command in notepad or IE...

Searching For A Text String Within A Folder
Hmm... dont know where to begin...

Execution:

Got a folder, thousands of files in the folder
Now there is a single string that i want to search for within the folder
(meaning all of the files in this folder) and hopefully get some results
and then from these results, i hope to save an INI or at leaste have a text box that shows me the results of WHICH exact files have the matching string that im looking for... if anybody could help id greatly appreciate it, thanks alot guys

coolshaps

Searching For Text In String Problem
Hey,
I'm trying to test to see if a string contains a certian word but I'm not having the best results.

I'm using:

text = "This is a string"
word = "ring"
results = InStr(text, word)

If Results <> 0 Then

msgbox "Word Found!"

Else

msgbox "Word Not Found!"

End If

But it doesn't match. How can I do the same thing but be able to match words inside of words?

Thanks,
Justin Sampson

Searching Text Files For A String
Is there a function in VB to search a text file for a specified string?

I've tried to input from the text file into a variable then use InStr to compare the two before looping and testing the next input - but it doesn't work...

If no-one has any ideas I can send this code and see if anyone knows what's wrong with it...

Thanks

Searching A Listview Or A Listbox For A String Of Text
in a listview i have the following information that will appear...

192.168.1.1 success 12ms
192.168.1.1 failed 0ms
192.168.1.1 success 15ms
192.168.1.1 success 20ms
192.168.1.1 failed 0ms
192.168.1.1 success 12ms

i want to be able to click on a command box and when i do it will search the listbox or listview to see how many of the ip address are successful. the information in column 1, 2, and 3 are variables... it is in a loop so the data in the variables a, b and c are keep on getting added to the listview control.
---------------
With ListView1.ListItems
Set list = .Add(, , a)
list.SubItems(1) = b
list.SubItems(2) = c
End With
----------------

any advice or tips will HELP alot, code would be even better thank you

Searching A String Within An Ini File.
Hi. Ive an ini file with a key and a value:

Key=2217

I have the value stored in a string variable called strString. What i wanna do is search within the INI file for other strString, i mean, search a string comparing with the one stored in strString.

Thanks!.

Searching For A String From A File
hello,
can any one solve my searching.
i have a database where i have placed a doc file in a table called personaldetails .
now i need a searchng tech to find out some key fields (eg. Name, Age, Location, etc) from the doc file.
and puting them in another table under fields name,age,location. please can any one solve my problem.
hope im clear with my recuirements.
thanks,
Five5

Searching For A String Inside A File
Hi...
Basically what I want to do is, read a file up to a particular word in that file, and store it in an array. Then, read the next part of the file up to that particular word and store it in an array and so on till the end of the file. something like the example file given below....

message1
message2
message3
endmessage <-delimiter. store everything above into an array
message4
message5
message6
endmessage <-delimiter. store everything above since the last delimiter
into an array.
...... and so on

Any ideas would be really helpful! Thanx!

How Would You Go About Searching For A Spefic String Is A File And Then Deleting That
How would you go about searching for a spefic string is a file and then deleting that string only?

Thank you!

Searching For The First Instance Of A String In A File. *RESOLVED*
I'm writing a piece of code that searches for the first instance of a string in a file, and return the offset in which the string is located. So far I have this:
VB Code:
Private Function GetSection(strFile As String, strSection As String) As LongOn Error GoTo ErrHandle        Open strFile For Binary Access Read As #1        Dim CurPosition As Long        Dim CurByte1 As Long, CurByte2 As Long, CurByte3 As Long, CyrByte4 As Long                 Do Until Curbyte4 = CByte(Asc(Mid(strSection, 1, 1))) And CurByte3 = CByte(Asc(Mid(strSection, 2, 1))) And CurByte2 = CByte(Asc(Mid(strSection, 3, 1))) And CurByte1 = CByte(Asc(Mid(strSection, 4, 1)))            If EOF(1) = True Then GoTo ErrHandle                        Curbyte4 = CurByte3            CurByte3 = CurByte2            CurByte2 = CurByte1             Get #1, CurPosition + 1, CurByte1            CurPosition = CurPosition + 1            Debug.Print CurPosition        Loop                GetSection = CurPosition    Close #1    Exit Function    ErrHandle:    GetSection = -1End Function
...but I'm not satisfied with the speed. Is there any way to speed it up? Better yet, can anyone suggest a better method of achieving this?

Searching File, Return String Postion
Is it possible to search a file for a string and return that string's position in the file?

Also, is it possible to read from X position to Z position in a file?

Thanks for your help!!!

Searching Text File For A Group Of Text.
Does anyone know the most efficient way to search a text file for a group of lines? For example, if the file was:

d = xxxxxx
a = xxxxxx
b = xxxxxx
d = xxxxxx
c = xxxxxx
e = xxxxxx
b = xxxxxx
where xxxxxx is any set of numbers.

and you wanted to search for the block of strings:

b = xxxxxx
d = xxxxxx
c = xxxxxx

Is there a quick and efficient way beside reading each line, matching against the first line, checking if the line following it is the second line, etc?

TIA
Bishop

Searching Text File
Greetings!

I am struggling to search a group of files for a specific string. I have used the Application.FileSearch in Excel VBA but I do not know of the alternative file search methods available in VB.

Your suggestions guys?

Searching Text File
is there a way to open a file, search through each line for the first 5 char to find a certain string, and if it's there then get the data to the right of it and edit it then save it back to the same location?!?!

i have the searching part, but i have no idea how to get the row, or column(if thats possible) or anything

thanks

Searching A Text File
I am writing a small program to screen pop our ACT! Database from our CTI program, I have tried using a method that searches the database using the SDK tools but it is too slow.

Another utility creates a CSV from the database which is used for another purpose but the CSV contains the phone numbers and the unique ID of each record and with the Unique ID i can tap straight into the database very quickly.

The CSV File containing about 8000 lines each with 8 fields, I would like to search in the file for the appearance of the phone number and then use the contents of field 8(Unique ID) further in the program. The phone number could appear in multiple lines and i would like to have it display a choice between these records.

I Am a newbie coder so any help with methods of searching this CSV would be greatly appreciated. Search speed is the key feature i need.

Please Help

SkreeM

Searching A Text File.
I have a text file that has the following: name, ID, average, Grade. What i want to do is have the user input an id and i want it to search the file for the id and if it's found i want it to output all the information related to that id number. i have the code to open so all i need to do is search it. the id's are between 1000 and 2000 would i just do a loop that runs through those numbers and if it finds a match have it out put or what? i'm clueless here.

Searching Through A Text File
I would like to be able to extract certain data from a text file for my program and have no idea how to do it. I've searched through all my VB books but I'm still confused.
Here's the scenario.

The external txt file contains comma delimited data that would look something like this:

Amount,11000,Amount,5000,Amount,1000,Amount,11000

The real thing contains more data, but the above is more specific to my needs.

I would like to set it up where the user would click a button, the program would go through this file (located in the root of the c: drive) and add up all of those amounts. Then return the total to a txt box.

I know this is a bit much, but any ideas would help.
Thanks!

Searching Through A Text File
Hey, i want to create a program that searchs through numbers in a text file, its for a hockey manager game (EHM if you've heard of it). Basically i want the program to display the Players name as well as their Potential number and Consistency number. Both numbers are two digits and are among several thousand numbers in the file. This is to make it easier to look at whose good in the draft so there will need to be some sort of code that only displays players born in a certain span of years such as 1986 - 1988.

If anyone could help me it would be much appreciated.

Thanks in advance

Searching For Text In A File
Hi All,

Using fileSystemObject or any other tool, how can I programmatically search for a text/word in a file.

Example: If I've 100 files in a folder and I want to search for a word "ERROR" exist in those files. Instead of using the windows "search files and folders", I want to write a program that can do it.

Cheers

Searching Text In A File
Ok, I know I posted about this before, and all were good suggestions, but none helped with my problem.

I have this bit of code -
10.1.6.248, EPCUSD_#401username, -, Y, 12/16/01, 13:50:29, 1, -, -, www.aol.com, -, 80, 90, -, 820, http, -, -, http://www.aol.com/popups/script/non_popup_memEd.js, -, Inet, 10054, 8389635

What I want to do is if I enter the username I want the program to show me all the web pages the person has been to in a list box.

I have the part where it finds the username already, but I cant get the part where it pulls the http://ect...

Any Ideas

Searching A Text File
How can I search a text file for individual keywords?

Text File Searching
how do i search a text file for a string?

Searching Text File
Hi,

I have a text file that is the result of a SQL query. How would I run a search on it according to something that a user puts in 2 two boxes (First Name and Last Name)? I then want to show the results in either a seperate form or a message box...

Thank you

Searching For Value In A Text File
I am creating a program to save data to a sequential access file and I am able to write data to the file using multiple textboxes. When I save the data to the file, one line of
text constitutes one record.

How can I open that file and perform a search for a value, then when it is found, populate the corresponding textboxes?

Any help is much appreciated!

Searching A Text File
To whom may help..

I am trying to write a program that will open one file #1, for input, read one line at a time. Open a second file #2, search thru text of file #2 for the information from file #1. I would also like to know how to set a search start and a search end and collect all information in between.

Thanx

Searching Through Text File?
How do I seacrh a string through a text file and when the text is found, separate small strings separated by semicolon( and display them in different textboxex.

Any help will be appreciated.
Thanks in advance.

Kinjal

Searching A Text File.
how do you search a text file for a certain word and then delete it from that text file in vb 5?

------------------
Mooose

Searching A Text File.
how do you search a text file for a certain word and then delete it from that text file in vb 5?

------------------
Mooose

Searching A Text File...
I created a database to store records and had no problem returning query results. However, I was told that we can't use Access and that the records need to be stored in a semi-colon delimited text file.

I have no clue whatsoever how to write a search. This file holds over 260,000 records so speed is possibly going to be a problem.

The file format is (semi-colon used because of name Format with comma):

ID; Lastname, FirstName; Sex; Date of Birth; Mother's Name

Originally with the database I selected a field to search and ran the related query with the criteria pulled from a text box. Now I'm thinking that I just need a text box and run the search for matches from that single text box.

A piece of code to get me started would be lovely. Or... if you have links to any tutorials that would be great to.

Thanks,

Phil

Searching A Text File?
Hi.
I have a text file which in which the lines are numbered this way:

[flightsim.0]
[flightsim.1]
-
-
[Flightsim.43]
and so....

I want to append some text to the textfile and wants to find out what the
highest number is, i.e. 43 and then add 1 to this number for the text to be
appended.

How do i do that?

Kind regards
Frank

Searching The Text Of A .pdf File
Hi, I am creating a project that involves displaying .pdf files. I would like to be able to have the user type in a search parameter/keyword and then search through a directory of .pdf files to see if their keyword is contained in any of the documents. Thank you in advance for any light you could shed on this.

Searching Through A Text File
I am doing my a level visual basic project, and have a problem. My program is for a shoe shop, with a stock control system and a till system. I add the details of a shoe (barcode, name, price) into a text file from my stock control system, and in my till system i want to input a certain barcode, where it will search for this barcode in the saved text file until it finds the corresponding record, and as a result brings the corresponding name and price of the shoe onto the screen. How do i do this? Do i need to separate each individual variable (barcode, name, price) by a comma? because when i open the text file it is stored like so: "Slipper 49.99 34583248 Ross  † 12365478" (These are two records, the "slipper" and "ross" are the names of the shoe, the 8 digit nos are the barcodes, and the other symbols are the price and quantity (?)) btw, i also need it to take one off the quantity each time i input the barcode (this is when a sale is made). Help would be much appreciated. Thanks, ross

Searching Through A Text File
 Ok, I am making an AIM program and the only way I know how to check for their username/pw is that when they connect it checks a text file on my computer (the server) for there name, so in englis hthis is what i want it to do:

search "c:/names.txt" , "username"
if it finds it then it sends oktoconnect, basically search a text file for a string and tell me whether or not it found it, sorry for that unexplanatory question but im in a hurry (= thanks in advance.

Searching A Text File
How can I search through a text file to find words or phrases. I need to search a log file for errors.

Thanks for any help you can provide.
Dave

Searching A Text File.
Hello all,

am trying to have a list of about 60,000 words(.txt file) searched and the results/partial match displayed in a text box. It will be used as a spelling reference for specialty words. I know that a list or combo box would do what I am looking for but populating it with that many entries would be a nightmare. Any ideas as to how I could accomplish this? I have tried to populate a table with the text file in a VCE form but it crashes the PPC and requires a hard reset. Any help/direction would be appreciated.

Rod

Searching A Text File
Does anyone know how to programmatically open an existing text file. Then search through a comma delimited file(like the portion below) for a string, '475'.

16,301,13981439,Z,IA0010,012040/
16,301,4756071,Z,IA00045,000000/
16,475,72363175,Z,IA00025,012040/
16,475,42736600,Z,IA00025,012050/

Thank you

No L c
VB Developer

Searching Text In A File
Hi,
I want to search a text in all the files in a directry.Please tell me if there is any easy way to do that.
Thanks,
-arun

Searching A Text File
need help with source code for an application which will accept a string from a text box and then search a text file for a matching string and then display its contents. if there is no matching string then the next compatable result should be displayed. can anyone help ?

Reading/Searching Text File
I tried searching the boards for the answer to this, but all i could find is bits and pieces. All I need is some simple code on how to read from a text file, and how to search through a text file, then take the items its found, and place them into variables.

For example

I have a text file called text.txt. The contents of the text file are as follows:

One
Two Three
Four Five Six

Basically what would be the code to pick out the string "Four Five" from the text file and place it into a variable. It would need to search through the entire file, to see if there are several instances of "Four Five".

Im sure this has been answered several times, but I couldnt find it

Searching Record In Text File
hi guys,

everything in this bit of code is doing fine...
but my combobox gets all the record in textfile, all i want is only the first column of the record...
give me some hints...
please help me..........

Private Sub cmd_Click(Index As Integer)
Dim f As Integer
Dim findstr As String
f = FreeFile
Select Case Index
Case 0 '-----CmdAdd---------
Open "c:sample.txt" For Append As #f
Write #f, Text1(0).Text; Text1(1).Text; Text1(2).Text
Close #f
'Call clear

'-----------problem here------------
Case 1 '------CmdSearch------
Open "c:sample.txt" For Input As #f
Do While Not EOF(1)
Input #f, findstr
Combo1.AddItem findstr
Loop
Close #f
'Call clear
End Select
End Sub

tnx

Searching And Modifying A Text File
OK, this is a pretty basic thing, and if search was working, I would probably find the answer in there. So bear with me, I know this has probably been covered a million times.

I'm writing a program that reads a text file, which is basically a bunch of records, displays them, allows the user to edit them, and saves the changes back in the file. (Obviously, this thing would be accomplished so much better with a database, especially since we're looking at uber files on the order of 1+ MB. But the file is already in text format so that's what I have to work with.)

So, my question is, I haven't done file handling in quite a while, and I'm not sure what the best way to go is. I was thinking about using the FileSystemObject to find and manipulate the file, then I thought about using the Word ojects, since it has find capabilities built in. I'm not that familiar with either of these objects, so I don't really know if one is better than the other, or if there's a better solution. If anyone can give me some tips, or point me to some info, I'd appreciate it.

Thanks.

Searching A Text File For For A Match
I have a form to disarm a security system I am building. On cmdDisarm_Click I want to check txtPassword for a match of a password in a .dat file. As I am new to VB I would greatly accept your help...

Roger

Help With Searching A Text File Using Wildcards
Firstly, im a newbie at coding.
secondly can a search be done on an opened text file using wildcards and then printing the result of the search to a text box?

e.g. i want to search for '*' (star being the wildcard and showing only whats between the appostrophies) then printing the result to a text box. i have used:

open "c:file1.text" for input as #1

but dont know how to actually perform the search.

hope this is clear and hope i get a quick reply.

thank you for your time in advance.

Copyright © 2005-08 www.BigResource.com, All rights reserved