asp 字符串截取函數(shù)
'*********************************************************
'函數(shù):cutStr[str(strlen)]
'參數(shù):str,待處理的字符串,strlen,截取的長(zhǎng)度
'作者:木木
'日期:2007/7/12
'描述:截取指定長(zhǎng)度的字符串
'示例:<%=cutStr("歡迎光臨阿里西西",5)%>
'*********************************************************
function cutStr(str,strlen)
If str = "" Then
cutStr = "cutStr函數(shù)異常:字符串為空"
exit function
End If
'------------來(lái)源長(zhǎng)度檢查
If strlen = "" Then
cutStr = "cutStr函數(shù)異常:長(zhǎng)度未指定"
exit function
End If
If CInt(strlen) = 0 Then
cutStr = "cutStr函數(shù)異常:長(zhǎng)度為0"
exit function
End If
'----------檢測(cè)來(lái)源字符長(zhǎng)度
dim l,t,c,i
l=len(str)
t=0
'----------循環(huán)截取字符
for i=1 to l
c=Abs(Asc(Mid(str,i,1)))
'------判斷是否漢字
if c>255 then
t=t+2
else
t=t+1
end If
'------判斷是否到達(dá)指定長(zhǎng)度
if t>=strlen then
cutStr=left(str,i)&".."
exit for
else
cutStr=str
end if
next
cutStr=replace(cutStr,chr(10),"")
end function
''*********************************************************
'函數(shù):strlen[str]
'參數(shù):str,待處理的字符串
'作者:木木
'日期:2007/7/12
'描述:判斷字符串長(zhǎng)度,漢字長(zhǎng)度為2
'示例:<%=strlen("歡迎光臨阿里西西")%>
'*********************************************************
Function strlen(str)
dim p_len
p_len=0
strlen=0
if trim(str)<>"" then
p_len=len(trim(str))
for xx=1 to p_len
if asc(mid(str,xx,1))<0 then
strlen=int(strlen) + 2
else
strlen=int(strlen) + 1
end if
next
end if
End Function
截取左邊的n個(gè)字符'*********************************************************
'函數(shù):LeftTrue(str,n)
'參數(shù):str,待處理的字符串,n,截取的長(zhǎng)度
'作者:木木
'日期:2007/7/12
'描述:顯示左邊的n個(gè)字符(自動(dòng)識(shí)別漢字)函數(shù)
'示例:<%=LeftTrue("歡迎光臨阿里西西",6)%>
'*********************************************************
Function LeftTrue(str,n)
If len(str)<=n/2 Then
LeftTrue=str
Else
Dim TStr
Dim l,t,c
Dim i
l=len(str)
t=l
TStr=""
t=0
for i=1 to l
c=asc(mid(str,i,1))
If c<0 then c=c+65536
If c>255 then
t=t+2
Else
t=t+1
End If
If t>n Then exit for
TStr=TStr&(mid(str,i,1))
next
LeftTrue = TStr
End If
End Function
相關(guān)文章
asp中Scripting.Dictionary字典對(duì)象使用示例
這篇文章主要介紹了asp中Scripting.Dictionary字典對(duì)象使用示例,本文包含創(chuàng)建、賦值、遍歷、判斷KEY等操作,需要的朋友可以參考下2014-08-08asp下如何在ADO服務(wù)器端利用好緩存技術(shù)?
asp下如何在ADO服務(wù)器端利用好緩存技術(shù)?...2007-04-04GetPaing 函數(shù)之a(chǎn)sp采集函數(shù)中用到的獲取分頁(yè)的代碼
GetPaing 函數(shù)之a(chǎn)sp采集函數(shù)中用到的獲取分頁(yè)的代碼...2007-09-09asp簡(jiǎn)單生成靜態(tài)的方法(模板標(biāo)簽替換)
asp簡(jiǎn)單生成靜態(tài)的方法,今天看了詞典工具里面的代碼,比較簡(jiǎn)單,需要的朋友可以參考下。2011-03-03可用的ASP無(wú)重復(fù)數(shù)字隨機(jī)函數(shù), 數(shù)組實(shí)現(xiàn), 并應(yīng)用于隨機(jī)顯示記錄集
可用的ASP無(wú)重復(fù)數(shù)字隨機(jī)函數(shù), 數(shù)組實(shí)現(xiàn), 并應(yīng)用于隨機(jī)顯示記錄集...2007-03-03一種理論上最快的Web數(shù)據(jù)庫(kù)分頁(yè)方法
一種理論上最快的Web數(shù)據(jù)庫(kù)分頁(yè)方法...2007-01-01關(guān)于Asp代碼與頁(yè)面的分離模板技術(shù)
使用模板實(shí)現(xiàn)ASP代碼與頁(yè)面分離,以后用asp就可以更方便的前后臺(tái)分開(kāi)制作2008-04-04asp將全角的字符轉(zhuǎn)變成半角字符,將半角轉(zhuǎn)變成全角d的代碼
2008-01-01