Using this in VB 2010:
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lines() As String = IO.File.ReadAllLines("filename.txt")
Dim foundIndex As Integer = Array.FindIndex(lines, Function(l) l.StartsWith(TextBox1.Text)) 'assuming TextBox1.Text = the part of the line before the =
lines(foundIndex) = Regex.Replace(lines(foundIndex), "(?<=" & TextBox1.Text & "=)\d+", TextBox2.Text) 'TextBox2.Text is the replacement number
Stop
'to rewrite the file:
'IO.File.WriteAllLines("filename.txt", lines)
End Sub
End Class
…but it keeps adding numbers after equals sign every time i save the text file.
I want it to replace everything on that line after equals sign.
I executed your code and It works unchanged:
If the file is
it will become
This is as you want it no?
Update 1
I replaced
With
Update 2
Regarding the issue with strings like “1e+007”. The part that matches the string after the “=” is currently [\d.]
Remember that there was a problem with numbers that had the decimal point like 3.25? This was solved by adding the “.” to the character class [\d] so it becomes [\d.]
Now anything that is a number “\d” and a “.” will match.
The new issue is solved in the same way. Now “e” and “+” should also be matched. Get it? So the character class now becomes [\d.e+]
Give it a go and let me know how it went.
Now it should also be clear how to modify the regex to match “BGS_LOGO.BIK” If you can solve that you understand what’s going on.