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

Replace , with ; in txt file

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
422
IT
Possible to replace , with ; in a big txt file?
naturally with a speed code.
Tks.
 
(Luca2009) is my other account.
98.000 row
The lenght of Each line have 123 chr
 
Why not just replace it in a Notepad? No code needed.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
This one was super easy to Google.

Code:
Dim FSO As FileSystemObject
Dim TS As TextStream
Dim TempS As String
Dim Final As String
Set FSO = New FileSystemObject
Set TS = FSO.OpenTextFile(YourInputFilenameHere, ForReading)
Do Until TS.AtEndOfStream
    TempS = TS.ReadLine
    'use the Replace function here
    TempS = Replace(TempS,"'",";")
    Final = Final & TempS & vbCrLf
Loop
TS.Close

Set TS = FSO.OpenTextFile(YourOutputFilenameHere, ForWriting, True)
    TS.Write Final
TS.Close
Set TS = Nothing
Set FSO = Nothing
 
Youi can trim that down somewhat

Code:
[COLOR=blue]Public Sub Rewrite(strIn As String, strOut As String)
    With New FileSystemObject
        .OpenTextFile(strOut, ForWriting, True).Write Replace(.OpenTextFile(strIn, ForReading).ReadAll, ",", ";")
    End With
End Sub[/color]

But, as ever with Sal21, the devil lies in the detail.

Sal21, why do you want to do this? From the description it sounds like this is some sort of data file - perhaps a csv. In which case, given that a comma is the more traditional seperator in a CSV, can your handling code not work with commas? Alternatively, if your handling code cannot work with (or be modified to work with) commas for some reason, perhaps you could have the file changed at source.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top