1 Dec 2010 16:44
How to escape special characters?
Hello All. I'm stuck at one point while trying to write a script. The problem was seen as a part of a larger script ... but I'll post the relevant part here. =====temp.txt===== a< b> c| d^ e% f& =====temp.txt===== =====temp.bat===== set /p "var=" < "temp.txt" echo "%var%" set "new=%var:<=<#%" set "new=%new:>=>#%" set "new=%new:|=|#%" set "new=%new:&=&#%" set "new=%new:^%=^%%#%" rem call set "new=%%new:^=^#%%" echo "%new%" =====temp.bat===== I am able to see the escaped characters < > | and & ... and I see the hash sign added after each of them. But somehow not able to figure out how to escape the % sign. And yet to attempt the ^ caret. Can someone kindly share the trick ? Thanks in advance, Parag Doke ------------------------------------(Continue reading)
. Will make it quit with non zero errorcodes in case of IO exceptions at
some later date. For now, this is what will work for me.
WScript.echo("Starting "+WScript.ScriptName);
var args=WScript.Arguments;
if (args.length < 3) {
WScript.echo("Usage: "+WScript.ScriptName+" FilePath
FindString/FindRegex NewString [NewFilePath]");
WScript.Quit(1)
}
var fso=WScript.CreateObject("Scripting.FileSystemObject");
var forReading=1;
var forWriting=2;
if (fso.GetFile(args.Item(0)).Size > 0) {
var text=fso.OpenTextFile(args.Item(0),forReading).ReadAll();
text=text.replace(args.Item(1),args.Item(2));
if (args.Item(3).length > 0) {
fso.OpenTextFile(args.Item(3),forWriting,true).Write(text);
} else {
WScript.echo(text);
}
}
WScript.echo("Finished "+WScript.ScriptName);
RSS Feed