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

Delete the last string in a txt file

Status
Not open for further replies.

Gti

Programmer
Jul 23, 2001
99
PT
I have a txt file and i want do erase the last string inside. How can i do it?

Any help

Tkx

;-)
 
By last string do you mean the entire text or a portion of a longer text? If its the entire text why not delete the file and do a save as for the new file to maintain the same name?

Just a suggestion.

Joanne
 

dim Fname as string ' the path to the file
dim Raw as string
dim lines() as string
dim i as long,upper as long

Open Fname For Binary As #1
Raw = String$(LOF(1), 0)'set a buffer to the same size as the file
'Read the entire file in one operation and close it
Get #1, 1, Raw$
Close #1

lines = split(raw,vbnewline)

raw = nothing

for i = 0 to upper - 1
raw = raw & lines(i) & vbnewline
next i

Open Fname For Binary As #1
put #1, raw
Close #1

hope this helps....

Troy Williams B.Eng.
fenris@hotmail.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top