几个ASP好用的自定义函数
来源:百度文库 编辑:神马文学网 时间:2024/05/01 17:16:34
cLeft(string, length) 返回指定数目的从字符串的左边算起的字符,区分单双字节。
如:
Dim MyString, LeftString
MyString = "文字测试VBSCript"
LeftString = cLeft(MyString, 10)
返回 "文字测试VB"。
MyRandc(n) 生成随机字符,n为字符的个数
如:
response.write MyRandn(10)
输出10个随机字符
MyRandn(n) 生成随机数字,n为数字的个数
如:
response.write MyRandn(10)
输出10个随机数字
formatQueryStr(str) 格式化sql中的like字符串.
如:
q = Request("q")
q = formatQueryStr(q)
sql = "select * from [table] where aa like ‘%"& q &"%‘"
GetRnd(min,max) 返回min - max之间的一个随机数
如:
response.write GetRnd(100,200)
输出大于100到200之间的一个随机数
函数代码:
<%
function cLeft(str,n)
dim str1,str2,alln,Islefted
str2 = ""
alln = 0
str1 = str
Islefted = false
if isnull(str) then
cleft = ""
exit function
end if
for i = 1 to len(str1)
nowstr = mid(str1,i,1)
if asc(nowstr)<0 then
alln = alln + 2
else
alln = alln + 1
end if
if (alln<=n) then
str2 = str2 & nowstr
else
Islefted = true
exit for
end if
next
if Islefted then
str2 = str2 & ".."
end if
cleft = str2
end function
function MyRandc(n) ‘生成随机字符,n为字符的个数
dim thechr
thechr = ""
for i=1 to n
dim zNum,zNum2
Randomize
zNum = cint(25*Rnd)
zNum2 = cint(10*Rnd)
if zNum2 mod 2 = 0 then
zNum = zNum + 97
else
zNum = zNum + 65
end if
thechr = thechr & chr(zNum)
next
MyRandc = thechr
end function
function MyRandn(n) ‘生成随机数字,n为数字的个数
dim thechr
thechr = ""
for i=1 to n
dim zNum,zNum2
Randomize
zNum = cint(9*Rnd)
zNum = zNum + 48
thechr = thechr & chr(zNum)
next
MyRandn = thechr
end function
function formatQueryStr(str) ‘格式化sql中的like字符串
dim nstr
nstr = str
nstr = replace(nstr,chr(0),"")
nstr = replace(nstr,"‘","‘‘")
nstr = replace(nstr,"[","[[]")
nstr = replace(nstr,"%","[%]")
formatQueryStr = nstr
end function
function GetRnd(min,max)
Randomize
GetRnd = Int((max - min + 1) * Rnd + min)
end function
%>
如:
Dim MyString, LeftString
MyString = "文字测试VBSCript"
LeftString = cLeft(MyString, 10)
返回 "文字测试VB"。
MyRandc(n) 生成随机字符,n为字符的个数
如:
response.write MyRandn(10)
输出10个随机字符
MyRandn(n) 生成随机数字,n为数字的个数
如:
response.write MyRandn(10)
输出10个随机数字
formatQueryStr(str) 格式化sql中的like字符串.
如:
q = Request("q")
q = formatQueryStr(q)
sql = "select * from [table] where aa like ‘%"& q &"%‘"
GetRnd(min,max) 返回min - max之间的一个随机数
如:
response.write GetRnd(100,200)
输出大于100到200之间的一个随机数
函数代码:
<%
function cLeft(str,n)
dim str1,str2,alln,Islefted
str2 = ""
alln = 0
str1 = str
Islefted = false
if isnull(str) then
cleft = ""
exit function
end if
for i = 1 to len(str1)
nowstr = mid(str1,i,1)
if asc(nowstr)<0 then
alln = alln + 2
else
alln = alln + 1
end if
if (alln<=n) then
str2 = str2 & nowstr
else
Islefted = true
exit for
end if
next
if Islefted then
str2 = str2 & ".."
end if
cleft = str2
end function
function MyRandc(n) ‘生成随机字符,n为字符的个数
dim thechr
thechr = ""
for i=1 to n
dim zNum,zNum2
Randomize
zNum = cint(25*Rnd)
zNum2 = cint(10*Rnd)
if zNum2 mod 2 = 0 then
zNum = zNum + 97
else
zNum = zNum + 65
end if
thechr = thechr & chr(zNum)
next
MyRandc = thechr
end function
function MyRandn(n) ‘生成随机数字,n为数字的个数
dim thechr
thechr = ""
for i=1 to n
dim zNum,zNum2
Randomize
zNum = cint(9*Rnd)
zNum = zNum + 48
thechr = thechr & chr(zNum)
next
MyRandn = thechr
end function
function formatQueryStr(str) ‘格式化sql中的like字符串
dim nstr
nstr = str
nstr = replace(nstr,chr(0),"")
nstr = replace(nstr,"‘","‘‘")
nstr = replace(nstr,"[","[[]")
nstr = replace(nstr,"%","[%]")
formatQueryStr = nstr
end function
function GetRnd(min,max)
Randomize
GetRnd = Int((max - min + 1) * Rnd + min)
end function
%>
几个ASP好用的自定义函数
几个常用的asp函数
(复用代码)经常用到的几个自定义函数: 监听·连接服务器·发送数据函数Send·接收数据函数Recv
用ASP读INI配置文件的函数
使用自定义函数对 ASP.NET 服务器控件进行验证
介绍几个ASP.NET中容易忽略但却很重要的方法函数
Asp Mid 函数的使用说明
Matlab 如何设置 自定义函数 的调用
fso应用中的几个小函数-asp教程-asp学习网
ASP用于分页的两个函数
php的几个配置文件函数
几个简单的prototype函数
感觉比较顺手的几个自定义键
几个自定义Eclipse模板的示例
提取Excel不重复值的自定义函数方案
ASP函数大全
比较两个单元格自定义函数
自定义多条件数组函数
与二分分治有关的几个函数
printk函数的几个消息记录等级
ASP教程:DateDiff函数和DateAdd函数
ASP日期和时间函数.....
ASP实现自定义标签模板_【我的天空】技术资源服务站
推荐几个好用的BBS