LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

几个常用的asp自造函数

admin
2010年7月23日 0:15 本文热度 5178

getrepeattimes(thechar,thestring) 得到一个字符串在另一个字符串当中出现几次的函数(新)

如:
response.write getrepeattimes("w",aspxhome.com)
response.write getrepeattimes("ww","wwwww")
在网上看到过一个checkthechar(thechar,thestring)函数,有个bug,在检测wwwww中有几个ww时,会错误的返回4个!

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之间的一个随机数

regreplace(str,regexstr,repalcestr) 对str 进行正则替换

如:
htmlstr = "123456"
htmlstr2 = regreplace(htmlstr,"<(.[^><]*)>","")
返回 htmlstr2 为123456

所有函数如下:
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

function getrepeattimes(thechar,thestring)
getrepeattimes = (len(thestring)-len(replace(thestring,thechar,"")))/len(thechar)
end function

function regreplace(str,patternstr,repstr)
dim newstr,regex
newstr = str
if isnull(newstr) then
regreplace = ""
exit function
end if
set regex = new regexp
regex.ignorecase = true
regex.global = true
regex.pattern=patternstr
newstr = regex.replace(newstr,repstr)
regreplace = newstr
end function


该文章在 2010/7/23 0:15:32 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved