在vbscript中覆盖值

在vbscript中覆盖值,vbscript,Vbscript,我必须用新值更新test.txt,即。删除值{AAA:777,BBB:888}并在标记中添加{ABC:123,GHN:246} 但是我的脚本将值附加为{AAA:777,BBB:888}{ABC:123,GHN:246 strFile="test.txt" Const ForAppending = 8 set objFSO = CreateObject("Scripting.FileSystemObject") set objFile = objFSO.OpenTextFile(strF

我必须用新值更新test.txt,即。删除值{AAA:777,BBB:888}并在标记中添加{ABC:123,GHN:246} 但是我的脚本将值附加为{AAA:777,BBB:888}{ABC:123,GHN:246

    strFile="test.txt"
Const ForAppending  = 8
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.OpenTextFile(strFile, ForAppending , True)
objFile.Write("{")
Dim dict
Set dict= CreateObject("Scripting.Dictionary")
dict.Add "ABC","123"
dict.Add "GHN","246"
k=dict.Keys
v=dict.Items
For j=0 to dict.Count-1
        objFile.Write(chr(34)&k(j)&":"&chr(34)&v(j)&chr(34)&",")
Next
==============

Test.txt

   [Valid]
   api = https://test.com
   Alpha = FALSE
   tag = {"AAA":"777" , "BBB":"888"}

我从未使用过dictionary对象/不知道如何使用,因此这可能不是一个可行的解决方案,这取决于您是否需要该对象提供的某些东西……但如果不使用正则表达式,您能不能简单地执行类似的操作

Dim fso, filecontent, file
Set fso = CreateObject("Scripting.FileSystemObject")
file = "C:\temp\test.txt"
filecontent = fso.OpenTextFile(file, 1, False).ReadAll
filecontent = Replace(filecontent,  "{""AAA"":""777"" , ""BBB"":""888""}", "{""ABC:""123"",""GHN:""246""}")
fso.OpenTextFile(file, 2, True).Write filecontent