人力検索はてな
モバイル版を表示しています。PC版はこちら
i-mobile

VBSの質問です
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)

●質問者: takanii
●カテゴリ:ウェブ制作
○ 状態 :終了
└ 回答数 : 1/1件

▽最新の回答へ

1 ● きゃづみぃ
●500ポイント ベストアンサー
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.人力検索はてなトップ
8.このページを友達に紹介
9.このページの先頭へ
対応機種一覧
お問い合わせ
ヘルプ/お知らせ
ログイン
無料ユーザー登録
はてなトップ