我正在使用广泛使用VBScript的产品,我需要解析字符串以提取特定数据。我知道如何用其他语言做到这一点,但需要用VBScript指向正确的方向。字符串中的VBScript返回值
这是我从文本文件中读取的字符串。
<PGConfiguration GPOName="Production Policy" GPODisplayName="Production Policy" GPOVersion="0" />
需要拉动GPOName =“I_NEED_THIS_DATA”之间的值。实例之间预计不会相同。
我有一个脚本,使用InStr()来确保GPOName = exists,并给我的字符位置。我已经能够用Mid()在GPOName =“之后启动,我不知道如何找到结束报价的计数或位置。
我是否正在使用InStr ()和Mid(),还是有更好的方法来处理这个(正则表达式可能??)
这段代码将打开文件,在内容中读取并弹出一个框中的前10个字符我试图去。我在哪里何去何从?
谢谢!如果哟
Dim objFSO, objTextFile, Stream, strSearchFor, strFileName, strLine, strPosition
' the file to check
strFileName = "C:\checkme.txt"
' what are we looking for
strSearchFor = "GPOName="
' create the object and open the file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Stream = objFSO.OpenTextFile(strFileName, 1, False)
Set objTextFile = objFSO.OpenTextFile(strFileName, 1, 0)
' read the first line with my data on it
strLine = objTextFile.ReadLine()
' do an InStr to get the position of the data
strPosition = InStr(strLine, strSearchFor)
' set the offset to 9 to get to the end of the ="
strPosition = strPosition + 9
' print of the first 10 characters after the GPOName=" match
wscript.Echo Mid(strLine,strPosition,10)
良好的通话,这正是我一直在寻找。谢谢! – OrganizedChaos