Sorry if this seems like I haven't searched, however I have. Maybe I'm not understanding something or maybe I just haven't found what I need. Anyway my question is this. How would I find multiple strings in a text file and replace them?
So far I've been able to find out how to replace a single string with:
However I have no idea how to do it for multiple strings. If for example I do something like:Code:Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim MyFile() As String = System.IO.File.ReadAllLines(filePath) Dim MySW As New System.IO.StreamWriter(filePath, False) Using MySW For Each Line As String In MyFile MySW.WriteLine(Line.Replace("Example 1", "eExample 1e")) Next End Using End Sub End Class
It replaces everything as per needed however it multiplies the strings by 3 and doesn't replace the multiplied strings anyway. So, how would I go about finding various strings in a text file and replacing them instead of only being able to do it for one string?Code:Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim MyFile() As String = System.IO.File.ReadAllLines(filePath) Dim MySW As New System.IO.StreamWriter(filePath, False) Using MySW For Each Line As String In MyFile MySW.WriteLine(Line.Replace("Example 1", "eExample 1e")) MySW.WriteLine(Line.Replace("Example 2", "eExample 2e")) MySW.WriteLine(Line.Replace("Example 3", "eExample 3e")) Next End Using End Sub End Class




Reply With Quote