hoge.txt
*********
a
b
*********
を置換して
*********
1
b
*********
というテキストファイルのしたいのでVBSスクリプトを組んだのですがうまくいきません
どうすればうまくいきますでしょうか?
Dim objFile ' 対象ファイル
Dim oldText ' 置換前テキスト
Dim newText ' 置換後テキスト
Dim objFSO ' ファイルシステムオブジェクト
Dim objRep ' 正規表現オブジェクト
Dim repText ' 置換後文字列
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("hoge.txt")
' テキストデータ読込
oldText = objFile.ReadAll
' 置換後文字列
repText = "1"
Set objRep = New RegExp
objRep.Multiline = True
' 正規表現パターンを指定する
objRep.Pattern = "a\n"
' テキスト変換
newText = objRep.replace(oldText, repText)
objFile.Close
' 書き込み
Set objFile = objFSO.CreateTextFile("aab.txt")
objFile.WriteLine (newText)
objFile.Close
Dim objFile ' 対象ファイル Dim oldText ' 置換前テキスト Dim newText ' 置換後テキスト Dim objFSO ' ファイルシステムオブジェクト Dim objRep ' 正規表現オブジェクト Dim repText ' 置換後文字列 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("hoge.txt") ' テキストデータ読込 oldText = objFile.ReadAll ' 置換後文字列 repText = "1" Set objRep = New RegExp objRep.Multiline = True ' 正規表現パターンを指定する objRep.Pattern = "a\r\n" ' テキスト変換 newText = objRep.replace(oldText, repText) objFile.Close ' 書き込み Set objFile = objFSO.CreateTextFile("aab.txt") objFile.WriteLine (newText) objFile.Close
vbsでの改行は
"\r\n"
となります。