I am working on replacing words in a text before showing all text in a richtextbox. The issue I am having is that the code seems to be reiterating through the loop, instead of a bulk text replacement.
here is my code:
text file path connection string
sql connection with using select * to fill datata table(repdt)
For Each textpath As String In Files.FileNames
RichTextBox1.Clear()
Dim newline = String.Empty
Dim regstr = String.Empty
For I As Integer = 0 To repdt.Rows.Count - 1
For Each line As String In File.ReadLines(textpath)
If line.Contains(repdt.Rows(I).Item("originaltext").ToString) Then
newline = line.Replace(repdt.Rows(I).Item("originaltext"), repdt.Rows(I).Item("replacementtext"))
regstr = String.Join(Environment.NewLine, line.Split(New Char() {ControlChars.Lf}, StringSplitOptions.RemoveEmptyEntries)).Replace(vbTab, "")
RichTextBox1.Text += newline + Environment.NewLine
End If
Next
Next
I am trying to make this into a library or text to replace.
What I have tried:
Initially, I was using this:
For Each textpath As String In Files.FileNames
RichTextBox1.Clear()
Dim regstr As String = String.Join(Environment.NewLine, System.IO.File.ReadAllText(textpath).Split(New Char() {ControlChars.Lf}, StringSplitOptions.RemoveEmptyEntries))
Dim replacestr As String = regstr.Replace("text", "text").Replace("text", "text").Replace("text", "text"). 'etc
RichTextBox1.Text = replacestr
Next
however, this requires coding everytime I want to replace something.