我是VBScript的新手。
如何在VBScript中使用shift
和unshift
函数?
答案 0 :(得分:4)
shift
和unshift
是JavaScript方法。它们在VBScript中不可用。如果您需要它们提供的功能,您基本上有两个选项:
使用.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, ",") & "]"