Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit Text file

Status
Not open for further replies.

lpb71

Technical User
Mar 10, 2004
57
GB
I am trying to write a script that reads a txt file, searches for branch=xxx (xxx= any 3 digit number) and replaces the line with branch=yyy) yyy=input variable.

the script below appends yyy onto xxx rather than replace - any ideas.

Test.123 is a text file that contains the text BRANCH=123

Const ForReading = 1
printer = inputbox("Enter Branch number - eg. B123")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\TEST.123", ForReading)
strContents = objFile.ReadAll
objFile.Close
Const ForWriting = 2
StrNewContents = Replace(strContents,"BRANCH=" + (MID(8 ,10)),"BRANCH=" + printer)
Set objFile = objFSO.OpenTextFile("C:\Test.123", ForWriting)
objFile.WriteLine strNewContents
wscript.echo strnewcontents
objFile.Close
 
There's something missing in your MID() statement.
Try MID(strContents,8,10).
Use & instead of + since you are concatenating strings.
 
Yep, thats done it - many thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top