asp实用function之大全

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

''==================取除左右括号============================FunctiongetReplace(Str)Str=Replace(Str,(,)Str=Replace(Str,),)getReplace=Trim(Str)EndFunction''==================取出数组中字符组成带括号的新字符=========FunctiongetNewStr(tempArr)temp=Fori=0ToUBound(tempArr)Iftemp=Thentemp=(&tempArr(i)&)Elsetemp=temp&,(&tempArr(i)&)EndifNextgetNewStr=tempEndFunction''==================生成数组放入sql查询语句==================FunctiongetInsql(tempArr)temp=ifisarray(tempArr)thenfori=0toubound(tempArr)iftemp=thentemp=''&tempArr(i)&''elsetemp=temp&,''&tempArr(i)&''endifnextendifgetInsql=tempEndFunction''================================================''''================字符串处理=======================''''================================================''''截取一定长度的字符串''Str为字符串,length为长度FunctioncutStr(Str,Length)Iflen(Str)LengthThencutStr=left(Str,Length)&...ElsecutStr=StrEndIfEndFunction''格式化文本输出,如空格、换行FunctionoutputStr_BR(str)IfstrThenoutputStr_BR=Server.HTMLEnCode(str)outputStr_BR=Replace(outputStr_BR,, )outputStr_BR=Replace(outputStr_BR,chr(13),br)ElseoutputStr_BR=EndIfEndFunction''字符安全处理FunctionSafeStr(str,IfTrim)Dimtemptemp=Replace(str,'','''')IfIfTrimThentemp=Trim(temp)EndIfSafeStr=tempEndFunction''不够宽度用空格填充“ ”,区分汉字(2个字长)、字母(1个字长)FunctionFormatLen(str,length)Dimtemp,tempLen,itemp=strtempLen=len(str)i=tempLenWhilei0Iflen(temp)0AndAsc(right(temp,1))0ThentempLen=tempLen+1EndIfi=i-1temp=left(temp,i)WendIftempLenlengthThentemp=Replace(Space(length-tempLen),, )EndIfFormatLen=str&tempEndFunction''返回半字长度FunctionlLen(str)Dimtemp,tempLen,itempLen=0temp=strWhileLen(temp)0IfAsc(Left(temp,1))0ThentempLen=tempLen+2ElsetempLen=tempLen+1EndIftemp=Right(temp,Len(temp)-1)WendlLen=tempLenEndFunction''返回定长的HTML格式空格FunctionHTMLSpace(length)HTMLSpace=Replace(Space(length),, )EndFunction''替换接收form内提交的字符串Functioncrequest(inputname)ifinputnamethencrequest=replace(trim(request(inputname)),'','''')elsecrequest=endifEndFunction''替换接收form内提交的字符串,主要为idFunctionirequest(inputname)irequest=replace(trim(request(inputname)),'','''')ifirequest=thenirequest=0EndFunction''替换接受翻页的页数Functionprequest(pageNumber)DimtmpPageNumbertmpPageNumber=request(pageNumber)IfIsNull(tmpPageNumber)OrtmpPageNumber=Thenprequest=1ElseIfIsNumeric(tmpPageNumber)Thenprequest=CInt(tmpPageNumber)Elseprequest=1EndIfEndIfEndFunction''从字符串str中删除字符串str1functiondeleteStr(str,str1)dimpospos=Instr(str,str1)ifpos0thendeleteStr=left(str,pos-1)&right(str,len(str)-pos-len(str1)+1)elsedeleteStr=strendifendfunction''str字符串左起补0functionleftZero(n,str)Dimzero_tag,zzero_tag=forz=0ton-1zero_tag=zero_tag&0nextleftZero=right(zero_tag&str,n)endfunction''判断手机号码是否合法functionisCellphone(str)iflen(str)=11andmid(str,1,1)=1andmid(str,2,1)=3thenisCellphone=trueelseisCellphone=falseendifendfunction''判断email地址是否合法functionisValidEmail(email)dimnames,name,i,cIsValidEmail=truenames=Split(email,@)ifUBound(names)1thenIsValidEmail=falseexitfunctionendifforeachnameinnamesifLen(name)=0thenIsValidEmail=falseexitfunctionendiffori=1toLen(name)c=Lcase(Mid(name,i,ifInStr(abcdefghijklmnopqrstuvwxyz_-.+,c)=0andnotIsNumeric(c)thenIsValidEmail=falseexitfunctionendifnextifLeft(name,1)=.orRight(name,1)=.thenIsValidEmail=falseexitfunctionendififLeft(name,1)=+orRight(name,1)=+thenIsValidEmail=falseexitfunctionendifnextifInStr(names(1),.)=0thenIsValidEmail=falseexitfunctionendififLeft(names(1),1)=+thenIsValidEmail=falseexitfunctionendififRight(names(1),1)=+thenIsValidEmail=falseexitfunctionendifi=Len(names(1))-InStrRev(names(1),.)ifi2andi3thenIsValidEmail=falseexitfunctionendififInStr(email,..)0thenIsValidEmail=falseendifendfunction''判断Fax是否合法PublicFunctionIsValidFax(fax)DimoRegExpSetoRegExp=NewRegExpoRegExp.Pattern=(^0\d{2,3}\-[1-9]\d{2,7}$)|(^[1-9]\d{2,7}$)|(^\(0[1-9]{2,3}\)[1-9]\d{2,7}$)oRegExp.IgnoreCase=TrueoRegExp.Global=TrueIsValidFax=oRegExp.Test(fax)SetoRegExp=NothingEndFunction''去除字符串中最后一个字符FunctioneraseLastChr(var_Str,var_character)IfIsNull(var_Str)Orvar_Str=TheneraseLastChr=ElseIfIsNull(var_character)Orvar_character=TheneraseLastChr=var_StrElseIfRight(var_Str,1)=var_characterTheneraseLastChr=Left(var_Str,Len(var_Str)-1)ElseeraseLastChr=var_StrEndIfEndIfEndIfEndFunction''======小数点前补0FunctionaddZeroPoint(str)tmpPosition=InStr(1,str,.,1)IftmpPosition=1Thenstr=0&straddZeroPoint=strEndfunction''================================================''''================字符数组处理======================''''================================================''''转换字符串到数组functionto_array(str,character)''changethexx,xx,xxtoarray(xx,xx,xx)ifisNull(str)thento_array=emptyelseiftrim(str)=thento_array=emptyelseto_array=split(str,character)endifendFunction''转换数组到字符串Functionto_String(arr,character)''changethearray(xx,xx,xx)toxx,xx,xxDimx,returnStrIfIsArray(arr)ThenForx=0ToUBound(arr)IfreturnStr=ThenreturnStr=arr(x)ElsereturnStr=returnStr&character&arr(x)EndIfNextto_String=returnStrElseto_String=EndIfEndFunction''从数组中删除functionremoveStr(str,arr)''deletethestringfromthearraydimkk=0redimtemp_arr(k)ifisArray(arr)thenfori=0toubound(arr)midstr=arr(

1 / 30
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功