CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2000
    Posts
    60

    Replace string in a file

    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


  2. #2
    Join Date
    Jan 2001
    Posts
    165

    Re: Replace string in a file


    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


  3. #3
    Join Date
    Aug 2000
    Posts
    60

    Re: Replace string in a file

    i am using vb5, is Replace function available in vb5?




  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Replace string in a file

    Replace is not available in VB5

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  5. #5
    Join Date
    Jan 2001
    Posts
    165

    Re: Replace string in a file

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured