E=mc2
asked on
Vbscript to search and replace numbers
I need a vbscript which will read a text file at c:\file folder and replace a set of numbers it finds with another set of numbers. The file is a csv, or a .txt file. For example i want to replace numbers 6789101112 with 12345678.
ASKER
What does blind link comments refer to?
Add a debugging line in to display the contents of strText to ensure it's what you expect. Sometimes there can be file encoding screwing this sort of thing up.
Try adding the Tristate value for Unicode when opening the file if strText looks wrong:
http://msdn.microsoft.com/en-us/library/314cz14s(v=vs.84).aspx
ie
Const ForReading = 1
Const FSO_Unicode = -1
Set objFile = objFSO.OpenTextFile("C:\Sc ript\file. CSV", ForReading, False, FSO_Unicode)
strText = objFile.ReadAll
Also, remove any "On Error Resume Next" you may be using in case an error is being thrown.
Try adding the Tristate value for Unicode when opening the file if strText looks wrong:
http://msdn.microsoft.com/en-us/library/314cz14s(v=vs.84).aspx
ie
Const ForReading = 1
Const FSO_Unicode = -1
Set objFile = objFSO.OpenTextFile("C:\Sc
strText = objFile.ReadAll
Also, remove any "On Error Resume Next" you may be using in case an error is being thrown.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, but rather than write it out in full or paste someone's work I sent the link which was subsequently deleted as a "blind comment".
I didn't know this wasn't allowed (my fault).
I didn't know this wasn't allowed (my fault).
ASKER
I want to give QPR a chance to provide a written script which works, so that i can give QPR the points instead, since we were not aware we could not include blind links.
That's ok just the close the question :)
I wasn't aware of the policy but am now.
Next time I'll know to provide the important part from the link and attribute the original author. Glad you got it working
I wasn't aware of the policy but am now.
Next time I'll know to provide the important part from the link and attribute the original author. Glad you got it working
ASKER
It works.
ASKER
I want replaced.
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.Fi
Set objFile = objFSO.OpenTextFile("C:\Sc
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "1223234343434 ", "102343433434334 ")
Set objFile = objFSO.OpenTextFile("C:\Sc
objFile.WriteLine strNewText
objFile.Close