本帖最后由 CrLf 于 2015-7-9 01:23 编辑
- @if (0==0) @end/*
- @echo off
- set /p line=行号:
- set /p oldstr=旧字符串:
- set /p newstr=新字符串:
-
- cscript -nologo -e:jscript %0 "%line:"=""%" "%oldstr:"=""%" "%newstr:"=""%"<1.txt>tmp.txt
- move /y tmp.txt 1.txt
- pause&exit
- */
-
- var line=parseInt(WScript.Arguments(0))-1
- var oldstr=WScript.Arguments(1).replace(/""/g,'"')
- var newstr=WScript.Arguments(2).replace(/""/g,'"')
- var text = []
-
- oldstr=oldstr.replace(/[\[\]\(\)\{\}\<\>\.\|\?\*\+\$\^]/g,'\\$&')
- newstr=newstr.replace(/[0-9\$]/g,'\\$&')
- text.push(WScript.StdIn.ReadAll().split(/\r?\n/g))
-
- if(line<text.length&&line>0){
- var re = new RegExp('\\s'+oldstr+'(?= |$)','g')
- text[line]=text[line].toString().replace(re,' '+newstr)
- }
-
- WScript.Echo(text.join("\r\n"))
复制代码
|