vbscript|VBS 中 Space 函数的应用

更新时间:2014-07-05    来源:php函数    手机版     字体:

【www.bbyears.com--php函数】

很多时候我们需要生成 重复的 N 个字符
一般人都会使用这样的方法
<%
Dim i, n, subString
n = 10
For i = 0 TO n
subString = subString & " "
Next
Response.Write(subString)
%>
其实是忽略了 VBS 里一个极有用的函数 Space
下面我用 Space 和 Replace 来实现上例功能
<%
Dim n, subString
n = 10
subString = Space(n)
subString = Replace(subString, " ", " ")
Response.Write(subString)
%>
如果你想更简单点的话 可以自己写个函数 比如
<%
Function SpacePlus(ByRef repeatString, ByRef repeatNumber)
SpacePlus = Replace(Space(repeatNumber), " ", repeatString)
End Function
Response.Write(SpacePlus(" ", 10))
%>

本文来源:http://www.bbyears.com/jiaocheng/7579.html