?
Solved

VBS How to remove double quotes from text file

Posted on 2011-10-07
3
Medium Priority
?
2,240 Views
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.
Thanks.
0
Comment
Question by:mbroad02
3 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 36932312
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.
0
 
LVL 59

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 36932368
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)
Else
  WScript.Echo "No filename specified."
  WScript.Quit
End If
If (WScript.Arguments.Count > 1) Then
  sOutfile = WScript.Arguments(1)
Else
  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
oInfile.Close
Set oInfile = Nothing

' Remove unwanted characters
sData = Replace(sData, """", "")

' Write file with any changes made
Set oOutfile = oFSO.OpenTextFile(sOutfile, ForWriting, True)
oOutfile.Write(sData)
oOutfile.Close
Set oOutfile = Nothing

' Cleanup and end
Set oFSO = Nothing
Wscript.Quit

Open in new window

~bp
2
 

Author Comment

by:mbroad02
ID: 36932989
Works great!!
Thanks
1

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

839 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