次のコードを使用して、各行の先頭に;
を追加できましたが、特定の単語が見つかった後に;
を追加したいとします。 [Abc]
。どのようにVBScriptを使用してこれを行うには?私は特定の単語を検索したいと思っています。開始時に
Const ForReading=1
Const ForWriting=2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set f = objFSO.OpenTextFile("D:\sam.txt", ForReading)
Do Until f.AtEndOfStream
strText = f.ReadLine
If Len(strText) = 0 Then
blnFound = True
MsgBox "blank line found"
strText = vbNewLine & strText
strContents = strContents & strText & vbCrlf
Else
strText = ";" & strText
strContents = strContents & strText & vbCrlf
End If
Loop
f.Close
Set f = objFSO.OpenTextFile("D:\sam.txt", Forwriting)
f.WriteLine strContents
f.Close
Sam.txt
には、いくつかの行が含まれています。
Hi, need help This is a sample text file [Abc] How are you Hope you are doing well!
だから私は、出力sam.txt
ファイルが内部のデータの下に持っていなければならないとします
Hi, need help This is a sample text file [Abc] ;How are you ;Hope you are doing well!
をお試しください。 'strText = replace(strText、" [Abc] "、" [Abc]; ")' –
私の投稿に返信していただきありがとうございます。 Sam.txtは、例えば こんにちはためのいくつかの行を含む。これは、あなたが あなたはよくやっている願っていますどのようにサンプルテキストファイル [Abcの] ある を助けが必要です! だから私は、ファイルsam.txt出力が内部のデータの下に持っている必要がありますしたい: - 、 こんにちは これを助ける必要はサンプルテキストファイル [Abcの] であり、どのようにして であり、あなたはよくやっている願っています! – sam