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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change string in text-file

Status
Not open for further replies.

Tranbjerg

IS-IT--Management
Jul 31, 2003
8
DK
Hi all

I need to make a script that can search for a substring in a text-file (notes.ini file) and replace it with another string. The string must not be case sensitive. I have found this script here that works, but its case sensitive.

Dim struser, notesini

Set FSO=CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")

Struser = WshNetwork.username
notesini = "C:\Documents and Settings\" & struser & "\Application Data\Notes\notes.ini"

Set TF=FSO.OpenTextFile(notesini,1)
inp=TF.ReadAll
out1=Replace(inp,"NAMES=Names.nsf","NAMES=C:\Documents and Settings\"+struser+"\Application Data\Notes\Names.nsf")
TF.close
Set TF=FSO.CreateTextFile(notesini,True)
TF.Writeline out
TF.Close

Regards
Jens
 
Try this:
Code:
out1=Replace(inp,"NAMES=Names.nsf","NAMES=C:\Documents and Settings\"+struser+"\Application Data\Notes\Names.nsf",1,-1,vbTextCompare)


Hope This Help
PH.
 
Sorry, but it didn't work. It just deleted everything in the file instead.

Jens
 
You had a typo in your 1st post: out1= instead of out=

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top