|
-
Jul 1st, 2002, 07:50 PM
#1
Thread Starter
Fanatic Member
Does Anyone know?
How can I delete a line from a textfile via code?
-
Jul 1st, 2002, 07:57 PM
#2
PowerPoster
The simplest way is using Replace function by replace those line with "" (Nothing) 
OR
open a new file by copy the first half (from begining till the starting point of the line you which to replace) and follow by copy the second half (from the end of the line which you wish to remove till the end of the file).
regards,
-
Jul 1st, 2002, 08:52 PM
#3
Thread Starter
Fanatic Member
ok.......
Say I found the word "BOB" in the fifth line of my textfile. Now I want to get rid of that line. How would I do that using the replace function? Would I have to seek to that line or something?
-
Jul 1st, 2002, 08:56 PM
#4
Hyperactive Member
You need to open the file, read all the lines into an array or something, find what you want to remove, remove it from the array, and then write the contents of the array back to the file.
We don't know what's wrong. . . So the best bet might be to remove something surgically.
-
Jul 1st, 2002, 09:10 PM
#5
PowerPoster
inthis case, i suggest to use the Regular Expression Check out the sample at RegExp
-
Jul 1st, 2002, 09:34 PM
#6
Thread Starter
Fanatic Member
An array like this?
VB Code:
Dim tmp as string
Dim temp () as string
temp () = Open "c:\windows\system\" & sDirname For Input As #1
Do Until EOF(1)
Line Input #1, tmp
Loop
Close #1
I'm kind of confused on this. How would I go about searching in an array for a string? Once I found it, I would just remove the # assigned to it in the array right?
-
Jul 1st, 2002, 10:14 PM
#7
PowerPoster
whatz do you wish to search from the "c:\windows\system\" & sDirname?
-
Jul 1st, 2002, 10:43 PM
#8
Thread Starter
Fanatic Member
oh!!
I just posted a piece of the code. That sDirname is a string that h as the folder name stored that it gets from a dirlistbox. Hows this:
Open "c:\windows\system\modernrock.txt" for input as #1
-
Jul 1st, 2002, 11:24 PM
#9
The picture isn't missing
Well...
VB Code:
dim a() as string
open "C:\something.txt" for input as #1
a = split(Input$(LOF(1),#1),vbcrlf) 'reads the whole file and splits lines to an array
close #1
open "C:\something.txt" for output as #1
for i = lbound(a) to ubound(a)
if a(i) <> "BOB" then 'do your searching here
print #1,a(i) 'if the line is not BOB then put it in the file (if it IS bob, then it doesn't
end if
next
close #1
Remember, if someone's post was not helpful, you can always rate their post negatively  .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|