顶楼代码这样写是不考虑特殊字符的
如果一定要兼容“!”字符,试试这样:- @set @n=0;/* & echo off
- set "space=3"
- cscript -nologo -e:jscript "%~0"<"1.txt" "0.txt" "%space%">"new.txt"
- pause & exit/b & rem */
-
- var arr = WScript.StdIn.ReadAll().replace(/\r\n$/, "").split("\r\n");
- var spc = WScript.Arguments(1);
- var fso = new ActiveXObject("Scripting.FileSystemObject");
- var txt = fso.OpenTextfile(WScript.Arguments(0), 1).Readall();
- var i = 0;
- txt = txt.replace(/\r\n$/, "") + "\r\n";
- txt = txt.replace(new RegExp("(.*\\n){" + spc + "}", "g"),
- function(s0) {
- var j = i % arr.length;
- s0 += arr[j] + "\r\n";
- i++;
- return s0
- }
- )
- WScript.StdOut.Write(txt)
复制代码
|