我有一部分剧本
strRel = "\Program Files (x86)\Symantec\Symantec Endpoint Protection\12.1.4100.4126.105\Bin64\"
strArray = Split(strRel,"\",-1,1)
strCom = strArray(1)
wscript.echo "strCom is " & strCom
将输出
strCom is Program Files (x86)
如何修改分割功能以便输出
strCom is \Symantec\Symantec Endpoint Protection\12.1.4100.4126.105\Bin64\
请注意,脚本处理各种目录,包含各种子文件夹。
答案 0 :(得分:1)
我会使用像demo这样的子字符串VB脚本,除了Mid(strRel,21)
答案 1 :(得分:1)
您可以限制Split
创建的字段数:
strRel = "\Program Files (x86)\Symantec\Symantec Endpoint Protection\12.1.4100.4126.105\Bin64\"
strArray = Split(strRel, "\", 3)
strCom = "\" & strArray(2)
WScript.Echo "strCom is " & strCom
答案 2 :(得分:1)
不确定这是否是您尝试做的事情,但如果您只想尝试剥离路径中的第一个文件夹,则可以使用此功能。它只获取第一个文件夹的长度,并在该点之后返回路径。
strRel = "\Program Files (x86)\Symantec\Symantec Endpoint Protection\12.1.4100.4126.105\Bin64\"
strArray = Split(strRel, "\")
' Add 2 to the length to account for the delimiter (\) and the one-baseness of Mid()...
strCom = Mid(strRel, Len(strArray(1)) + 2)