aliasmortal
Member
- Joined
- Feb 26, 2008
- Messages
- 6
- Programming Experience
- 1-3
Newbie help needed.
I am loading a text file into a string searching for a specific word and then replacing it, this works fine. My problem is, I need to search and find the word I am looking for but get the entire length of it, remove it, and replace it with the new text.
Below is my example, any help would be great.
[myinfo]
name="qwerty"
location="123 somewhere ave" <----e.g. This could be any length
occupation="whatever"
[nextinfo]
CODE SAMPLE:
*** newText gets passed to this function ***
Private Sub sysprepModification(ByVal newText As String)
Const ForReading = 1
Const ForWriting = 2
Dim objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile = objFSO.OpenTextFile("C:\info.inf", ForReading)
Dim strText = objFile.ReadAll
RichTextBox1.Text = strText
objFile.Close()
Dim strNewText = Replace(strText, "Name=*", "Name=" & newText)
objFile = objFSO.OpenTextFile("C:\info.inf", ForWriting)
objFile.WriteLine(strNewText)
objFile.Close()
RichTextBox2.Text = strNewText
End Sub
I am loading a text file into a string searching for a specific word and then replacing it, this works fine. My problem is, I need to search and find the word I am looking for but get the entire length of it, remove it, and replace it with the new text.
Below is my example, any help would be great.
[myinfo]
name="qwerty"
location="123 somewhere ave" <----e.g. This could be any length
occupation="whatever"
[nextinfo]
CODE SAMPLE:
*** newText gets passed to this function ***
Private Sub sysprepModification(ByVal newText As String)
Const ForReading = 1
Const ForWriting = 2
Dim objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile = objFSO.OpenTextFile("C:\info.inf", ForReading)
Dim strText = objFile.ReadAll
RichTextBox1.Text = strText
objFile.Close()
Dim strNewText = Replace(strText, "Name=*", "Name=" & newText)
objFile = objFSO.OpenTextFile("C:\info.inf", ForWriting)
objFile.WriteLine(strNewText)
objFile.Close()
RichTextBox2.Text = strNewText
End Sub