What is the comand to replace text in an open ascii file? Please help.
Printable View
What is the comand to replace text in an open ascii file? Please help.
Read your text into a string variable or array whichever best suits your needs and then use instr to find each instance of the text you want to replace. Then use mid$ to replace the text and write it back out to the file.Quote:
Originally posted by JohnL55:
What is the comand to replace text in an open ascii file? Please help.
[This message has been edited by Lemp (edited 02-03-2000).]
The mid() function can be a little combersome for lots of replacements especially if you're replacing the same text (like in a multi find replace program :))
read to a string then use the replace function.
FileString = Replace(FileString, OldText, NewText)
For some reason this function is not that well known
When writing FileString back to the document, double quotes are added to the start and end of the string. The double quotes are not in the string to start with.Quote:
Originally posted by Paul282:
The mid() function can be a little combersome for lots of replacements especially if you're replacing the same text (like in a multi find replace program :))
read to a string then use the replace function.
FileString = Replace(FileString, OldText, NewText)
For some reason this function is not that well known
Take the words NEW DATA. When I write it back, it comes out "NEW DATA". If I replace in the string the Quotes with nothing it does not get rid of the quotes because they are not really in the string.
It depends on what you use to write the string back to the doc. If you use print it just plain dumps it, if you use write it puts quotes around things. If you look up the Write function it mentions that. That's how I get around it. Write is convienant when writing to a CSV but I use the Print one more often.