Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello:
I am trying to program this in VB.NET. I am relatively new to programming
I have two text files
Text file 1:
a1
a1
b1

Text file 2:
a1
b1

I need to report that one of 'a1's is deleted in text file 2
Any help is appreciated !

Thanks

What I have tried:

Hello:
I am trying to program this in VB.NET. I am relatively new to programming
I have two text files
Text file 1:
a1
a1
b1

Text file 2:
a1
b1

I need to report that one of 'a1's is deleted in text file 2
Any help is appreciated !

Thanks
Posted
Updated 19-Apr-16 21:18pm
Comments
ZurdoDev 19-Apr-16 20:11pm    
Start by using System.File, https://msdn.microsoft.com/en-us/library/system.io.file(v=vs.110).aspx.

Read in the text and start comparing line by line.
Member 12471735 20-Apr-16 19:23pm    
Hello:
This is what I had tried before posting here
Logic was to count number of instances in file 1 and store it an array and do the same in file 2
Finally compare these two arrays for each line item
I know it is such a round about and a very bad logic

I then tried the following code which I found in one of the forums

Dim tosearch As New System.IO.StreamReader(TextBox1.Text)
Dim searchin = IO.File.ReadAllText(TextBox1.Text)
Dim search As String
search = tosearch.ReadLine

Do While Not tosearch Is Nothing
Dim matchquery = From Word In searchin
Where Word = search
Select Word

Dim count As Integer = matchquery.Count()
'MsgBox(count)
Loop
PIEBALDconsult 19-Apr-16 21:14pm    
http://www.codeproject.com/script/Awards/View.aspx?cid=358
Patrice T 19-Apr-16 22:50pm    
What have you done ?
Looks like HomeWork.
Member 12471735 20-Apr-16 19:24pm    
Hello:
I just posted what I had tried..
It is not a homework

1 solution

HI,

try this:

C#
Dim directory As [String] = "C:\Whatever\"
Dim linesA As [String]() = File.ReadAllLines(Path.Combine(directory, "FileA-Database.txt"))
Dim linesB As [String]() = File.ReadAllLines(Path.Combine(directory, "FileB-Database.txt"))

Dim onlyB As IEnumerable(Of [String]) = linesB.Except(linesA)

File.WriteAllLines(Path.Combine(directory, "Result.txt"), onlyB)
 
Share this answer
 
Comments
Member 12471735 20-Apr-16 19:45pm    
Hi:
Thanks for your help
The output of this code would be
a1
b1
which is the difference between the two files
I also want to print that one a1 is deleted
Hope it makes sense on what am looking for

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900