Board index » Visual Studio » Replace , with ~ in a file

Replace , with ~ in a file

Visual Studio44
I have a file (mine.ini) where I need to replace every "," with a "~".

How do this?

Thanks


-
 

Re:Replace , with ~ in a file

"gonzosez" <adf>wrote in message



Quote
I have a file (mine.ini) where I need to replace every "," with a "~".

How do this?



Look up the Open and Input # statements in help (MSDN) and also the

Replace() function.





-

Re:Replace , with ~ in a file

Quote
I have a file (mine.ini) where I need to replace every "," with a "~".

How do this?



Dim FileNum As Long

Dim TotalFile As String

' Let VB generate the file channel number

FileNum = FreeFile

' Reads the whole file into memory all at once

Open "c:\path\to\mine.ini" For Binary As #FileNum

TotalFile = Space(LOF(FileNum))

Get #FileNum, , TotalFile

Close #FileNum

' Do the replacement

TotalFile = Replace$(TotalFile, ",", "~")

' Let VB generate the file channel number

FileNum = FreeFile

' Save the contents of the TotalFile variable back out

Open "c:\path\to\mine.ini" For Output As #FileNum

Print #FileNum, TotalFile

Close #FileNum



Rick





-