一、定义简单数组
在ASP中,有两种定义和初始化数组的方法,如下所示:'方法一:
MyArray = Array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
'数组大小由初始化元素个数决定。
'方法二:
Dim myArray(2) '指定数组大小
myArray(0)="Monday"
myArray(1)="Tuesday"
二、数组动态扩展dim myArray()
redim myArray(20) '将数组大小重新定义为20
redim Preserve myArray(i) 'Preserve …
笔者在编程过程中,遇到需要将字符串按照非数字分割的情况。将编写的代码记录下来,供有需要的朋友参考。theString="12345$678910#13579*246810"
if theString<>"" then
for i=1 to len(theString)
if not isnumeric(mid(theString,i,1)) then
theString=replace(theString,mid(theString,i,1),",")
end if
next
if instr(theString,",")=0 then
response.write the…
在ASP中使用正则表达式过滤掉非中文字符。函数构建代码如下:Function RegExpTest(strng)
i = 0
Set regEx = New RegExp
regEx.Pattern = "[^\u4e00-\u9fa5]"
regEx.IgnoreCase = True
regEx.Global = True
RegExpTest= regEx.Replace(strng,"")
End Function
在文章内容添加时,我们通常需要将内容中的链接去掉。本文为大家提供一个使用正则表达式去掉链接的方法。代码如下:Function RemoveLinks(str)
Set ra = New RegExp
ra.IgnoreCase = True
ra.Global = True
ra.Pattern = "]+>(.+?)<\/a>"
RemoveLinks = ra.replace(str,"$1")
END Function
注意:此方法是去掉锚点链接,而不是去掉文本网址。
ASP中没有专门的程序延迟执行函数。我们可以自己编写函数,实现程序的延迟执行。
参考代码一:Response.Buffer = True
' Setup the variables necessary to accomplish the task
Dim TimerStart, TimerEnd, TimerNow, TimerWait
' How many seconds do you want them to wait...
TimerWait = 5
' Setup and start the timers
TimerNow = Timer
TimerStart = TimerNow
TimerEnd = TimerStart + TimerWait
' Keep it in…
ASP函数rnd()
函数rnd()返回一个0到1之间的随机数。 使用方法如下:response.write rnd() '其可能的返回值:0.2357746
如果你想用rnd()函数来返回某一范围内的整数,比方说大于等于0而小于等于特定整数upperbound的数字,你可以使用如下方法:response.write int((upperbound+1)*rnd)
例如,下面的语句将返回一个0和5之间的整数,包括0和5: response.write int((5+1)*rnd)
如果你想获得一个处在某个范围内的随机数,…
在ASP中,如果想将字符串aaaabbaaaaaa中所有的aa替换为a,用replace执行一次操作后,结果为aabbaaa,依然含有aa。那么怎样让程序再继续进行替换,直到结果中不再含有aa呢?其实我们只要用个简单的循环语句就可以了。代码如下:theText="aaaabbaaaaaa"
x="a"
Whileinstr(theText,x&x)<>0
theText=replace(theText,x&x,x)
Wend
response.writetheText'返回结果:abba
在Asp网页中,使用301永久重定向,将页面“自动转向”到新的页面。示例如下:Response.Status="301 Moved Permanently"
Response.AddHeader "Location","technology/"
Response.End
如果需要带参数,示例:id=request.QueryString("id")
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","technology/show.asp?id="&id
Response.End