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

Text Stream

Status
Not open for further replies.

bluebytez

Programmer
Dec 20, 2001
39
MY
How do I add text into the middle of a text file ?
I was trying to do it via textstream, but OpenAsTextStream would only allow ForReading only, ForWriting only, or ForAppending only.
I need to look for certain occurences in the text file and replace it with other text. For that I would need to read and write on the same file which TextStream does not allow.
Any ideas ?
 
Dim objFso as FileSystemObject
Dim objTs as TextStream
Dim strIn as string
Set objFs = New FileSystemObject
Set objTS = objFS.OpenTextFile(strFileName, _
ForReading, False, TristateFalse)
strIn = objTS.ReadAll ' Including CrLf
objTS.Close
strIn = Replace(strIn,"AAA","BBB")
Set objTS = objFS.OpenTextFile(strFileName, _
ForWriting, True, TristateFalse)
objTS.Write strIn ' Write Everthing
objTS.Close
Set objTS = Nothing
Set objFS = Nothing Compare Code (Text)
Generate Sort in VB or VBScript
 
if my text file is not too big,

[ol][li]I would open the file for reading[/li]
[li]read the entire file into a string variable[/li]
[li]close the file[/li]
[li]do my search and replace on the string variable[/li]
[li]open the file for output (for writing)[/li]
[li]print (write) the string variable into the file[/li][/ol]
 
Thanks for the prompt reply, but I am afraid I missed out one detail. The text file that I am processing is 86 MB in size. It is actually a data file for an old legacy system that I am trying to convert to RDBMS. That's why I need to clean up the text file. I believe VB's string variable will not be able to support 86 MB of text data.
What other options should I try ?
 
Actually the string variable will support 86 MB (max 2 billion) if your pagimg file can handle it. 86MB will be 172MB in memory because VB converts the Acii to Unocode conversion internally. :)

Do you not have the disk storage to write the file out to a new file until everything checks out and you can delete the old and rename the new?

This is a simple "father to son" run. Compare Code (Text)
Generate Sort in VB or VBScript
 
Thanks John,
That's what I have done, " the father to son " method.
Works great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top