How to make a complex replacement between strings in 2 text files

  • Thread starter Thread starter khattabcosmology
  • Start date Start date
K

khattabcosmology

Guest
Good evening,

I have 2 text files,

the first one includes ID and name of employees, like this:

33445Michael

54321Tony

75454Sara

The second one includes some information about the employees, like this:

33445 23 years old

54321 30 years old

75454 27 years old


what i need to do is replacing the IDs inside the 2nd file with the related names inside the first file.

i tried the following code but it does not work correctly:

Dim file1 As String = ("firstFile.txt")
Dim file2 As String = ("secondFile.txt")

Dim IDs As New StreamReader(file1 )
Dim Names As New StreamReader(file2)



Dim ID As String
Dim EmoloyeeName As String

Using reduceditems As StreamWriter = New StreamWriter(Application.StartupPath + "\NewFile.txt", True)
Do While (True)

Dim ioline1() As String = IO.File.ReadAllLines(file1)
For i As Integer = 0 To file1.Length - 1

ID= Mid(ioline1(i), 1, 5)
EmoloyeeName = Mid(ioline1(i), 6, 15)
next
Dim newline As String = EmoloyeeName

If System.IO.File.Exists(file2 ) Then

Dim lines As String = file2 .ReadLine()
If lines.Contains(ID) Then
lines = newline
reduceditems.WriteLine(lines)





ElseIf lines.Contains(ID) = False Then

End If


End If


Next


Loop
End Using

End If

Please, i need your help and advise.

Thanks

Khaled

Continue reading...
 
Back
Top