Problem with VB Script to convert comma to Pipe delimited
Previously I received the attached code to convert a file from comma to pipe delimited. However I recently realized that the script is also converting commas embedded within fields such that a street address of "100 Main Street, Suite 1A" gets changed to "100 Main Street| Suite 1A".
I need the code to change only those commas that are delimiters between fields, not the ones that are part of the data.
Sample input and out files are attached.
' Define needed constantsConst ForReading = 1Const ForWriting = 2Const TriStateUseDefault = -2' Get input file name from command line parm, if 2 parms entered' use second as new output file, else rewrite to input fileIf (WScript.Arguments.Count > 0) Then sInfile = WScript.Arguments(0)Else WScript.Echo "No filename specified." WScript.QuitEnd IfIf (WScript.Arguments.Count > 1) Then sOutfile = WScript.Arguments(1)Else sOutfile = sInfileEnd If' Create file system objectSet oFSO = CreateObject("Scripting.FileSystemObject")' Read entire input file into a variable and close itSet oInfile = oFSO.OpenTextFile(sInfile, ForReading, False, TriStateUseDefault)sData = oInfile.ReadAlloInfile.CloseSet oInfile = Nothing' Replace commas (,) with pipes (|)sData = Replace(sData, ",", "|")' Write file with any changes madeSet oOutfile = oFSO.OpenTextFile(sOutfile, ForWriting, True)oOutfile.Write(sData)oOutfile.CloseSet oOutfile = Nothing' Cleanup and endSet oFSO = NothingWscript.Quit