當前位置:編程學習大全網 - 編程語言 - 怎麽把章節漢字變成數字,會正則表達式的大神快來拯救世界~

怎麽把章節漢字變成數字,會正則表達式的大神快來拯救世界~

已經給妳寫好了,但需要傳ptnList.txt文件給妳,直接發到這裏會被規範刪除,妳留個郵箱吧。

貼出其中VBS代碼:

Dim?fso,fd,fl,f,fdpath,findstr,repstr,ul,u

On?Error?Resume?Next

If?WScript.Arguments.Length>=1?Then

fdpath?=?WScript.Arguments(0)

Else

fdpath?=?InputBox("請輸入文件夾路徑:","第壹個參數")

If?fdpath?=?""?Then?WScript.Quit

End?Iftmp?=?Split(WScript.ScriptFullName,"\")

tmp(UBound(tmp))?=?"ptnList第章.txt"

usrListPath?=?Join(tmp,"\")

Set?ul?=?ParseJson(GetFile(usrListPath))Set?fso?=?CreateObject("scripting.filesystemobject")

Set?fd?=?fso.GetFolder(fdpath)

Set?fl=fd.Files

For?each?f?in?fl

doreplace?f.Path

Next

MsgBox?"替換結束,請查看結果。",,"提示"Function?ParseJson(strJson)

Set?htmlfile?=?CreateObject("htmlfile")

Set?owindow?=?htmlfile.parentWindow

owindow.execScript?"var?getJson?=?false","javascript"

On?Error?Resume?Next?'如果strJson不是json字符串,下面這句會出錯

owindow.execScript?"getJson?=?true;?var?json_obj?=?"?&?strJson,?"javascript"

On?Error?Goto?0

If?Not?owindow.getJson?Then

MsgBox?"獲取json失敗,退出vbs",,"tya提示"

ie.Quit

WScript.Quit

End?If

Set?ParseJson?=?owindow.json_obj

End?Function?'讀取文件-->替換內容-->保存文件

Function?doreplace(filepath)

Dim?FileName,?Find,?ReplaceWith,?FileContents,?dFileContents,?regEx

Set?regEx=New?RegExp?FileName?=?filepath?

FileContents?=?GetFile(FileName)

For?Each?u?In?ul

regEx.Pattern?=?u.ptn

regEx.IgnoreCase?=?True

regEx.Global?=?True

ReplaceWith?=u.rep

FileContents?=?regEx.replace(FileContents,ReplaceWith)

Next

WriteFile?FileName,?FileContents

End?Function

'讀取文件?

Function?GetFile(FileName)?

If?FileName<>""?Then?

Dim?FS,?FileStream?

Set?FS?=?CreateObject("Scripting.FileSystemObject")?

On?Error?Resume?Next?

Set?FileStream?=?FS.OpenTextFile(FileName)?

GetFile?=?FileStream.ReadAll?

End?If?

End?Function?

'寫文件?

Function?WriteFile(FileName,?Contents)?

Dim?OutStream,?FS?

On?Error?Resume?Next?

Set?FS?=?CreateObject("Scripting.FileSystemObject")?

Set?OutStream?=?FS.OpenTextFile(FileName,?2,?True)?

OutStream.Write?Contents?

End?Function

  • 上一篇:ProE二次開發(wildfire5.0),選擇函數ProSelect(),工程中如何選擇粗糙度?怎麽
  • 下一篇:神奇的莫比烏斯帶教學設計
  • copyright 2024編程學習大全網