a.htmlをb.htmlへ変換させるvbsを組みたいのですがどうすればいいのでしょうか?
a.html
*********************
<input type="checkbox">
hoge
<input type="checkbox">
hoge
<input type="checkbox">
hoge
<input type="checkbox">
hoge
**********************
を
b.html
**********************
<input id="box1" type="checkbox">
hoge
<input id="box2" type="checkbox">
hoge
<input id="box3" type="checkbox">
hoge
<input id="box4" type="checkbox">
hoge
**********************
よろしくお願いします
Dim objFile ' 対象ファイル
Dim oldText ' 置換前テキスト
Dim newText ' 置換後テキスト
Dim objRep ' 正規表現オブジェクト
Dim repText ' 置換後文字列
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("a.html")
oldText = objFile.ReadAll
repText = ""
Set objRep = New RegExp
objRep.Multiline = True
objRep.Pattern = "<input "
objRep.Global = True
newText = objRep.replace(oldText, repText)
Set objFile = objFSO.CreateTextFile("b.html")
objFile.WriteLine (newText)
Dim objFile ' 対象ファイル Dim objFile2 ' 出力ファイル Dim objFSO ' ファイルシステムオブジェクト Dim k Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("a.html") Set objFile2 = objFSO.CreateTextFile("b.html") k=1 Do Until objFile.AtEndOfLine = True strText = objFile.ReadLine if instr(strText,"<input ") > 0 then strText = replace (strText,"<input ","<input id=""box" & k & """ ") k=k+1 end if objFile2.WriteLine ( strText ) Loop objFile.Close objFile2.Close
正規表現で連番を付与させることは できませんので、1行ずつ読んで 変換していくことになります。
コメント(0件)