List Info

Thread: Re: Delete specific line from a textfile




Re: Delete specific line from a textfile
country flaguser name
United States
2008-03-05 10:28:20

Thanks for that Rob, you were correct in physically removing the line.
I had never come across the Replace function before, this is good as I
know exactly the string I am removing, hence got it down to ...

strsamplefind = "214 TRIUMPH 633D-190G-XB0 1290650 NONE KEN4_TRIUMPH"

Open "C:text.txt"; For Binary As #1
strInput = Input$(LOF(1), #1)
Close #1

strOutput = Replace(strInput, vbCrLf & strsamplefind, "")

Open "c:output.txt" For Output As #2
Print #2, strOutput
Close #2

Looks neater if nothing else !
>From the web, it looks like .net has a command to pull a specific line
number from a textfile, must be a common ask ?

__._,_.___
.

__,_._,___
RE: Re: Delete specific line from a textfile
country flaguser name
United States
2008-03-08 22:21:33

> Thanks for that Rob, you were correct in physically removing
> the line. I had never come across the Replace function before...

While this will work, it would be better to use the TextStream object
and iterate through x times copying lines from the old file to a
replacement file, until you get to the offensive line, then skip that
line copying. This will avoid the HUGE memory footprint that a very
large text file will consume. I usually use the TextStream method when
the file might be large, cause it doesnt significantly impact the
performance of the rest of the system unless you do a "ReadAll" (which
is a really bad idea for large files).

-Shawn

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )