checking for duplicate lines in text files (vb.net)
I currently have an application that prints four text box values to a text file. I was wondering of there was anyway to scan the text file before writing to it, to check to see if that entry already exists. Can anybody help me with this?
|
grep
... Oh, wait! This is a stupid Windows question on Linux Questions! |
What does grep mean
|
Kdr, the description of the programming forums here clearly states that any sort of programming questions are allowed...
Quote:
mrobertson, grep is a utility in Linux that is used specifically for what you are trying to do. It looks for text in a file... For your solution, you'll probably have to write your own routine. It should be pretty simple, though. Just read in the file line by line and compare to what you are looking for... |
would you be able to give me some sample syntax for how to compare?
Here is the code for how I rread the line in: Code:
FileOpen(10, "C:\Documents and Settings\alogue\Desktop\Coil PDI\PDI.txt", OpenMode.Append) |
Hmmm.... that looks like the old VB 6 way of working with files. Is there a reason you're not using the System.IO.StreamReader/StreamWriter objects? I would assume they should be available in VB .Net.
Anyway, in C# an easy way of doing this might be something like: Code:
public bool TextExistsInFile(string sText, string sFilename) |
I stand corrected.
|
How would this be done in vb.net?
|
You can do this using the same objects and methods, just format it to be in VB syntax...
No offense, but this is a pretty simple algorithm. A little reading on the .Net documentation is all you should need to do. |
I underdtand the algorithm, I just do not understand how the sText would be defined. I realize that it is the text on the line that I am reading but how would you define it. Same with sLine?
|
You use that funciton like so:
Code:
|
Quote:
Code:
if not ExistsInFile(Parameter 1, Parameter 2) |
All times are GMT -5. The time now is 08:31 AM. |