VBS How to remove double quotes from text file

Posted on 2011-10-07
Last Modified: 2012-05-12
I Have a text file which contains several fields which have " around each field.  I would like to be able to remove the quotes.  Sample:  "field1" "field2"  etc.

A short VBS script should take care of it.
Question by:mbroad02
    LVL 92

    Expert Comment

    by:Patrick Matthews
    Yes, a short script could handle it, but be advised that that can introduce new problems.

    For example, in a delimited text file, any field entries that themselves contain the delimiter character will typically have to be wrapped in a text qualifier (which is usually double quote).

    You should post a smallish sample file here.
    LVL 51

    Accepted Solution

    If you do truly want to just remove all double quotes from the file, here's my template approach.  Save this as a VBS file, and then run it passing it one or two command line parms.  If only one file is specified on the command line then it will make the changes and overwrite that file.  If two filenames are specified then it will make the changes on the first file but write them to the second file - great for testing.

    ' Define needed constants
    Const ForReading = 1
    Const ForWriting = 2
    Const TriStateUseDefault = -2
    ' Get input file name from command line parm, if 2 parms entered
    ' use second as new output file, else rewrite to input file
    If (WScript.Arguments.Count > 0) Then
      sInfile = WScript.Arguments(0)
      WScript.Echo "No filename specified."
    End If
    If (WScript.Arguments.Count > 1) Then
      sOutfile = WScript.Arguments(1)
      sOutfile = sInfile
    End If
    ' Create file system object
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    ' Read entire input file into a variable and close it
    Set oInfile = oFSO.OpenTextFile(sInfile, ForReading, False, TriStateUseDefault)
    sData = oInfile.ReadAll
    Set oInfile = Nothing
    ' Remove unwanted characters
    sData = Replace(sData, """", "")
    ' Write file with any changes made
    Set oOutfile = oFSO.OpenTextFile(sOutfile, ForWriting, True)
    Set oOutfile = Nothing
    ' Cleanup and end
    Set oFSO = Nothing

    Open in new window


    Author Comment

    Works great!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
    Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now