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!

Find & Replace Text

Status
Not open for further replies.

NickC111

Technical User
Sep 23, 2010
44
GB
Good Afternoon

I have a simple text document where I want to find and replace certain text.

**0915750600*CW3*STORE AND PREMISES*

I want to use find and replace - Find CW3 and replace with 970 - write a new file with the new changes

Any ideas?
 
Perhaps this thread will help:
thread329-1672632
 
Load the file in notepad. use find and replace (ctrl+h). save file :)

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Thanks for the thread - I have come up with the following code
Code:
Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Text.txt", ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "CH1", "*901*")

Set objFile = objFSO.OpenTextFile("C:\Text.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close

Its finds "CH1" and replaces it with *901* in the test text file

I want to change the script so that its reads from a cross-reference and it finds a match enter the new data from the cross-reference table

Example

Test.txt

CH1
DR4
GH7
SX7
GE9
SP1

Cross-Reference Table

CH1 = *901*
DR4 = *856*
GH7 = *658*
SX7 = *025*
GE9 = *986*
SP1 = *756*

So the script reads the cross-reference where it finds a match in the text file it replaces it with the corresponding entry

Finds CH1 and replaces it with *901*

Any help would be great

Thanks







 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top