So Im working on a program that shows this.
This is the code that I use two show the SA and PLATINUM text because on the file they are not the only characters on the line, like this:
…..
set username=sa
set password=platinum
…..
code to search only those two words.
Dim lines() As String = IO.File.ReadAllLines("C:NTMBackup1NTMBackup4.bat")
Dim userIndex As Integer = Array.FindIndex(lines, Function(s) s.Contains("utilizador"))
Dim psswrdIndex As Integer = Array.FindIndex(lines, Function(s) s.Contains("password"))
Me.txtusr.Text = lines(userIndex).Substring(lines(userIndex).IndexOf("="c)).Substring(1)
Me.txtpassowrd.Text = lines(psswrdIndex).Substring(lines(psswrdIndex).IndexOf("="c)).Substring(1)
What I want is to change the “sa” and “platinum” textboxes and then save it on the file using the buttom, to change it on the flie like:
…..
set username=something
set password=something
…..
I made this code but it inserts on the whole line and it delete everything that is on the file, I think Im not using the correct code.
Dim FILE_NAME As String = "C:NTMBackup1NTMBackup4.txt"
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objwriter As New System.IO.StreamWriter(FILE_NAME)
objwriter.WriteLine(Txtusr.Text)
objwriter.WriteLine(Txtpasswrd.Text)
objwriter.Close()
MsgBox("done!")
Else
MsgBox("fail!")
End If
If anyone got an idea please say anything, thanks
The post VS 2010 How to replace the words on a file ? appeared first on IT Answers.