Click here to Skip to main content
15,899,566 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Format a Row in DataGrid Pin
Pablo.ar7-Dec-04 13:16
Pablo.ar7-Dec-04 13:16 
GeneralRe: Format a Row in DataGrid Pin
Anonymous7-Dec-04 16:30
Anonymous7-Dec-04 16:30 
QuestionSingleton Strongly-Typed Dataset? Pin
Mark Farmiloe7-Dec-04 7:14
Mark Farmiloe7-Dec-04 7:14 
GeneralKeypress mimic Mouse click Pin
TAlvord7-Dec-04 5:59
TAlvord7-Dec-04 5:59 
GeneralReading/Writing large files Pin
Zenly7-Dec-04 1:45
Zenly7-Dec-04 1:45 
GeneralRe: Reading/Writing large files Pin
Dave Kreskowiak7-Dec-04 3:52
mveDave Kreskowiak7-Dec-04 3:52 
GeneralRe: Reading/Writing large files Pin
Zenly7-Dec-04 5:12
Zenly7-Dec-04 5:12 
GeneralRe: Reading/Writing large files Pin
Dave Kreskowiak7-Dec-04 5:51
mveDave Kreskowiak7-Dec-04 5:51 
Zenly wrote:
Idealy I want to replace lines of a file without having to read it into a variable then write it back out to a new file.

I'm not going to ask why you tried to read a 200MB file into a string variable then.


Zenly wrote:
Idealy I want to replace lines of a file without having to read it into a variable then write it back out to a new file. I also want a solution that is quick and ifficient.

Then process the file one line at a time. The solution is to open TWO file streams. One for reading the source file and the other for writing the destination file. Read the source file, using .ReadLine(), into a string variable, call your Replace function on it, then write the new line out to your second file. Keep doing this until you reach the end of the source file, see the example code for the reference to Peek. If Peek returns anything less than 0, you've reached the end of the file.
Private Sub ProcessFile(ByVal sourceFilePath As String, ByVal destFilePath As String)
    If File.Exists(lvFilePath) = True Then
        Dim lineToProcess As String
        Dim srcStream As New StreamReader(sourceFilePath)
        Dim destStream As New StreamWriter(destFilePath)
 
        Do While (srcStream.Peek >= 0)
            lineToProcess = srcStream.ReadLine()
            Replace(lineToProcess, "d:\directory1", "")
            destStream.WriteLine(lineToProcess)
        Loop
        srcStream.Close()
        destStream.Close()
    End If
End Function

* This code is not guaranteed to compile, let alone work. It is intended as a guide only, to be worked out and fixed by you, the reader!


RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

GeneralRe: Reading/Writing large files Pin
Zenly7-Dec-04 6:40
Zenly7-Dec-04 6:40 
GeneralUrgent - ThreadPool Pin
cwayman7-Dec-04 0:27
cwayman7-Dec-04 0:27 
GeneralHANDLES - Windows Messages Pin
rdges6-Dec-04 22:42
rdges6-Dec-04 22:42 
GeneralHelp required with Regular Expressions Pin
vbvjain6-Dec-04 18:52
vbvjain6-Dec-04 18:52 
QuestionMain Menu Bar Color? Pin
Sumit Domyan6-Dec-04 18:00
Sumit Domyan6-Dec-04 18:00 
AnswerRe: Main Menu Bar Color? Pin
Dave Kreskowiak7-Dec-04 5:56
mveDave Kreskowiak7-Dec-04 5:56 
GeneralAuto-scroll ListView Pin
xshi0056-Dec-04 16:48
xshi0056-Dec-04 16:48 
GeneralRe: Auto-scroll ListView Pin
Pablo.ar7-Dec-04 0:54
Pablo.ar7-Dec-04 0:54 
GeneralRe: Auto-scroll ListView Pin
xshi0057-Dec-04 9:05
xshi0057-Dec-04 9:05 
GeneralRe: Auto-scroll ListView Pin
Pablo.ar7-Dec-04 9:18
Pablo.ar7-Dec-04 9:18 
GeneralRe: Auto-scroll ListView Pin
xshi0057-Dec-04 9:45
xshi0057-Dec-04 9:45 
GeneralRe: Auto-scroll ListView Pin
Pablo.ar7-Dec-04 13:06
Pablo.ar7-Dec-04 13:06 
GeneralRe: Auto-scroll ListView Pin
xshi0057-Dec-04 14:49
xshi0057-Dec-04 14:49 
GeneralRe: Auto-scroll ListView Pin
kostasvel7-Dec-04 2:31
kostasvel7-Dec-04 2:31 
GeneralRe: Auto-scroll ListView Pin
xshi0057-Dec-04 9:06
xshi0057-Dec-04 9:06 
Generalarrays Pin
Anonymous6-Dec-04 13:32
Anonymous6-Dec-04 13:32 
GeneralRe: arrays Pin
WartHog0006-Dec-04 13:49
WartHog0006-Dec-04 13:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.