Collectives on Stack Overflow. Learn more. How do I delete a specific line from text file in C? Ask Question. Asked 8 years ago. Active 4 months ago. Viewed 72k times. Improve this question. Michael Petrotta Hansen Derrick Hansen Derrick 1 1 gold badge 2 2 silver badges 5 5 bronze badges.
Add a comment. Active Oldest Votes. Improve this answer. AndersK AndersK And if I want to do that on several files of several thousands of lines? Not a very good solution WoodrowBarlow yes, seemed to have forgotten that. Reed Kimble - I don't know the maximum size of file 1. It could contain 1 line or it could contain 20, lines, or , lines and so on.
However it's unlikely to be more than a couple of thousand lines most of the time. I wasn't aware of List Of String , I'll look that up thanks. I'm thinking it miight be better importing both files into a dummy table in a DB, then joining them and exluding the lines I don't want from file 1.
Then export the data back to a text file containing the data I need. Given those sizes I would say that my initial proposition should be ok, though likely not nearly as fast as loading them into a database first and then asking it to do the comparison. Cheers : Reed Kimble - "When you do things right, people won't be sure you've done anything at all".
Is there a fast way to load the entire file into a list? The StreamReader is probably fastest. It might work since you only need to compare the entire string and not a portion of it I didn't think about that You can try it StreamReader filePath While Not sr. EndOfStream result. Add sr. ReadLine End While sr. Close Return result End Function Reed Kimble - "When you do things right, people won't be sure you've done anything at all".
In your case I would create an array Generic List or arraylist from File1 while reading it. If I had done, then I would remove the lines using a streamreader to read and only write the lines if the rows are not the array direct in using a streamwriter in file2.
Even if File 2 is then Gb it would go as long as you have that free on disk as you start. Cor Success Cor. I tried with , lines in file 2 and 12, lines in file 1. Contains x Then sw. Close sw. Close End Sub And it took a couple of minutes to write out the new file, which is too slow so I'm going to load the files into a DB and do the comparison there which should take a fraction of the time.
Will you let us know how long it took, because I have the idea that you will be disapointed by that approach. Success Cor. Tuesday, September 15, PM. Cor With the same 2 files it takes 10 seconds to produce the file by importing them to a DB. Which is much better. Thank you for replying, nullptr. Still,it doesn't work. Thank you very much! We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.
You're trying to visit a URL that doesn't currently exist on the web. Most likely, a member posted a link a long time ago to a web page that has since been removed. It's also possible that there was a typo when posting the URL. We redirect you to this notice instead of stripping out the link to preserve the integrity of the post. Answered by nullptr in a post from 9 Years Ago. Refer to Jump to Post. Answered by Ancient Dragon 5, in a post from 8 Years Ago.
Jump to Post.
0コメント