0
对于这个代码,我有在使用MID和INSTR功能的问题:如何从字符串中选择和裁剪某些字符?
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set file = objFSO.OpenTextFile("sample.txt" , ForReading)
Const ForReading = 1
Dim re
Dim controller
Dim action
Set re = new regexp
re.pattern = "(contextPath\s*?[+]\s*?[""][/]\w+?[?]action[=]\w+?[""])"
re.IgnoreCase = True
re.Global = True
Dim line
Do Until file.AtEndOfStream
line = file.ReadLine
For Each m In re.Execute(line)
var = m.Submatches(0)
'I am having a problem with the next two lines:
controller = Mid(var, 1, InStr(var, "contextPath\")) & "[?]action[=]\w+?[""]n"
action = Mid(var, 1, InStr(var, "contextPath\s*?[+]\s*?[""][/]\w+?[?]action[=]")) & """"
Wscript.Echo "controller :" & controller
Wscript.Echo "action: " & action
Next
Loop
在文本文件“sample.txt的”:
contextPath+"/GIACOrderOfPaymentController?action=showORDetails"
contextPath +"/GIACPremDepositController?action=showPremDep"
contextPath+ "/GIACCommPaytsController?action=showCommPayts"
(注意,加上旁边的空间(+)号)
我怎样才能使输出看起来就像这样:
controller: GIACOrderOfPaymentController
controller: GIACPremDepositController
controller: GIACCommPaytsController
action: showORDetails
action: showPremDep
action: showCommPayts
试过,它的工作。谢谢! – ladiesman1792 2014-12-04 07:01:52
“actions.Add”K“'有什么用? – ladiesman1792 2014-12-04 07:20:41
@ ladiesman1792,在将数据添加到'scripting.dictionary'时,必须在每个包含的元素中包含一个*唯一键*。对于发布的代码,我有习惯将*“K”*前缀作为视觉线索来标识添加*键*的位置。但它不是必需的。 – 2014-12-04 07:45:45