问题:我正在尝试替换文本文件中的键/值对。值更改时,键保持不变。除了以键名开头的单行之外,我不想修改其他任何行。
我目前所拥有的:
Sub REPLACESESSIONID()
Dim CONTENT, SESSIONID, WORKINGDIR As String
SESSIONID = "urn:uuid:A750ADE2355E6EAA2315397874423"
SESSION = FreeFile()
' ESTABLISH WORKING DIRECTORY
WORKINGDIR = Environ("AppData") & "\PROJECT"
' READ SESSION.TXT AND STORE AS VARIABLE
Open WORKINGDIR & "\SESSION.txt" For Input As #SESSION ' Open file
CONTENT = Input(LOF(SESSION), SESSION)
Close #SESSION
' REPLACE SESSIONID* WITH NEW SESSIONID
CONTENT = Replace(CONTENT, "SESSIONID*", "SESSIONID;" & SESSIONID)
' WRITE CHANGES TO SESSION.TXT
Open WORKINGDIR & "\SESSION.txt" For Output As #SESSION
Print #SESSION, CONTENT
Close #SESSION
End Sub
我知道替换不允许通配符,但是不确定如何进行。
SESSION.txt的内容:
SESSIONID;urn:uuid:A7AGBDE25436EAA231532239423
ROLENAME;Local_Unix_Admin