Click to See Complete Forum and Search --> : Replace string in a file
stlai
April 20th, 2001, 10:50 AM
Hi,
I have a very large file where i want to delete all quotation marks before and after a comma,
What is the fast way to do that?
Thanks,
Sue
Kdev
April 20th, 2001, 11:05 AM
Dim strFileName as string
Dim strHuge as string
Dim ln as Long
Dim strFileContent() as string
Dim iFile as Integer
iFile = FreeFile
strFileName = "path\to\your\file.ext"
Open strFileName for input as #iFile
ln = FileLen(strFileName)
strHuge = Space(ln)
strHuge = input(ln, iFile)
Close #iFile
strHuge = Replace(strHuge, "," & chr(34), "")
strHuge = Replace(strHuge, chr(34) & ",", "")
iFile = FreeFile
Open strFileName for output as #iFile
print #iFile, strHuge
Close #iFile
--Some code thanks to sharathms--
-K
stlai
April 20th, 2001, 11:16 AM
i am using vb5, is Replace function available in vb5?
Iouri
April 20th, 2001, 03:14 PM
Replace is not available in VB5
Iouri Boutchkine
iouri@hotsheet.com
Kdev
April 20th, 2001, 03:27 PM
Well since replace isn't in VB5 then I will give you similar code using the InStr function. I hope that function is in VB5.
Dim strFileName as string
Dim strHuge as string
Dim ln as Long
Dim strFileContent() as string
Dim iFile as Integer
Dim lPos as Long
iFile = FreeFile
strFileName = "path\to\your\file.ext"
Open strFileName for input as #iFile
ln = FileLen(strFileName)
strHuge = Space(ln)
strHuge = input(ln, iFile)
Close #iFile
lPos = InStr(strHuge, "," & chr(34))
while lPos <> 0
strHuge = Left(strHuge, lPos - 1) & mid(strHuge, lPos + 2)
lPos = InStr(strHuge, "," & chr(34))
wend
lPos = InStr(strHuge, chr(34) & ",")
while lPos <> 0
strHuge = Left(strHuge, lPos - 1) & mid(strHuge, lPos + 2)
lPos = InStr(strHuge, chr(34) & ",")
wend
iFile = FreeFile
Open strFileName for output as #iFile
print #iFile, strHugeClose #iFile
--Some code thanks to sharathms--
-K
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.