Hi
The following code will open a text file and read each line of text and then search a list box for that line of text, if found it will replace the line of text in the text file with the next item in the list box. (Strange I know)
The code works fine but the problem is, if the line of text in the text file is “sup” the code will pick up any item in the list box that contains the word “sup” (example: supporter, supply, etc..). I have been playing with Regex code so only to pick up the exact word and have the following expression to only pick up the exact word but where in the code do I place it.
The following code will open a text file and read each line of text and then search a list box for that line of text, if found it will replace the line of text in the text file with the next item in the list box. (Strange I know)
Code:
Dim lineIn As String
Dim i As Integer
Dim listString As String
Dim arrLines() As String = File.ReadAllLines(TextBox2.Text, System.Text.Encoding.UTF8)
For j As Integer = 0 To arrLines.Length - 1
lineIn = arrLines(j)
For i = 0 To ListBox1.Items.Count - 1
listString = ListBox1.Items.Item(i)
If InStr(listString, lineIn) Then
If i < ListBox1.Items.Count - 1 Then
arrLines(j) = ListBox1.Items.Item(i + 1)
End If
End If
Next i
Next
File.WriteAllLines(TextBox2.Text, arrLines, System.Text.Encoding.UTF8)
Code:
Dim regex As Regex = New Regex(("\b" & lineIn & "\b"))