Basically the whole idea of the whole exercise was to open a "CSV" file but with ~ (tilde separator) in UTF-8 encoding, remove all commas from it, then change the tildes to commas and save it as ANSI encoded pure CSV file without excessive commas.

Here is the full code for it in case someone interested in such a scenario or just replacing a string in a text file:

 Code:
 
Break ON
$strSrcFile = "C:\kix\test1.txt"
$strDstFile = "C:\kix\test2.txt"
$strFind = ","
$strReplace = "."

$strFind2 = "~"
$strReplace2 = ","
$objWord = CreateObject("Word.Application")
$RC = $objWord.Documents.Open($strSrcFile)
$RC = $objWord.ActiveDocument.Content.Find.Execute($strFind, , , , , , , , , $strReplace, 2)
$RC = $objWord.ActiveDocument.Content.Find.Execute($strFind2, , , , , , , , , $strReplace2, 2)
$RC = $objWord.ActiveDocument.SaveAs($strDstFile,2)
$RC = $objWord.Application.Quit



Edited by green78 (2010-12-23 01:06 AM)