本帖最后由 pcl_test 于 2015-9-9 11:38 编辑
- //&cls&dir /b "1.htm"|cscript.exe -nologo -e:jscript "%~f0"&pause&exit/b
-
- var loadText = function (FileIn,Charset){
- var stm = new ActiveXObject('ADODB.Stream');
- stm.Type = 2;
- stm.Mode = 3;
- stm.Charset = Charset;
- stm.Open();
- stm.LoadFromFile(FileIn);
- stm.Position = 0;
- return stm.ReadText;
- }
- var saveText = function (str,FileOut,Charset){
- var stm = new ActiveXObject('ADODB.Stream');
- stm.Type = 2;
- stm.Mode = 3;
- stm.Charset = Charset;
- stm.Open();
- stm.WriteText(str);
- return stm.SaveToFile(FileOut,2);
- }
-
- while(!WScript.StdIn.AtEndOfStream) {
- var txt = '';
- var f= WScript.StdIn.ReadLine();
- var fn = f.replace(/\.[^\.]*$/,'');
- var txttmp = loadText(f,'utf-8').match(/\[\{"qid":.+?\}\]/)[0];
- var txttmp = txttmp.replace(/</g,'「').replace(/>/g,'」').replace(/「[^」]*」|\\\\r|\\\\n/g,'');
- var m = txttmp.match(/\{[^\}]+?\}/g);
- for (var i=0;i<m.length;i++){
- var qid = m[i].replace(/.+"qid":(\d+).+/,'$1');
- var title = m[i].replace(/.+?"title":"(.+)","content.+/,'$1');
- var content = m[i].replace(/.+?"content":"(.+)","optionnum.+/,'$1').replace(/\\n|\\t/g,'');
- var content = content.replace(/(B、|C、|D、)/g,'\r\n$1');
- var answer = '答案:'+m[i].replace(/.+?answer":"([^"]).+/,'$1');
- txt +=qid+'、'+title+'\r\n'+content+'\r\n'+answer+'\r\n\r\n'
- }
- saveText(txt,fn+'.txt','gb2312');
- }
复制代码
|