我是 VBScript 的新手。
如何在 VBScript 中使用shift
和运行?unshift
shift
并且unshift
是 JavaScript 方法。它们在 VBScript 中不可用。如果您需要它们提供的功能,您基本上有 2 个选择:
使用 .Net 类System.Collections.ArrayList
:
Set a = CreateObject("System.Collections.ArrayList")
a.Add "a"
a.Add "b"
a.Add "c"
WScript.Echo "[" & Join(a.ToArray, ",") & "]"
'insert at beginning of array
a.Insert 0, "z"
WScript.Echo "[" & Join(a.ToArray, ",") & "]"
'remove from beginning of array
v = a(0)
a.RemoveAt 0
WScript.Echo v
WScript.Echo "[" & Join(a.ToArray, ",") & "]"
使用标准 VBScript 数组的包装器模拟该功能。CArray
我前段时间实现了这样一个包装器( ):
Set a = New CArray
a.Items = Array("a", "b", "c")
WScript.Echo "[" & Join(a.ToArray, ",") & "]"
'insert at beginning of array
a.InsertFirst "z"
WScript.Echo "[" & Join(a.ToArray, ",") & "]"
'remove from beginning of array
v = a.RemoveFirst
WScript.Echo v
WScript.Echo "[" & Join(a.ToArray, ",") & "]"