ASP 支持中文的len(),left(),right()的函數(shù)代碼
更新時間:2010年05月30日 01:43:58 作者:
在用ASP處理文字時。系統(tǒng)自帶的字符串長度檢測函數(shù)有時候也不是很好用。
比如一個漢字也只會算一個字節(jié),在排版時如果全是漢字,好說,反正沒什么差別,但是如果被操作的字符串有漢字又有英文字母時,就不方便了,以下三個函數(shù)可以代替ASP自帶的相關(guān)函數(shù)。
也有注意的地方,如果用在循環(huán)中,因不變量“i”也是常用于循環(huán)的變量,執(zhí)行以下函數(shù)時,“i”的值會發(fā)生變化,如果是調(diào)用他的循環(huán)中用到相同的變量,會產(chǎn)生未知的結(jié)果,請換用其它變量名。
以下用法和len(),left(),right()一樣。
程序代碼
Function Strlength(Str)
Temp_Str=Len(Str)
For I=1 To Temp_Str
Test_Str=(Mid(Str,I,1))
If Asc(Test_Str)>0 Then
Strlength=Strlength+1
Else
Strlength=Strlength+2
End If
Next
End Function
Function Strleft(Str,L)
Temp_Str=Len(Str)
For I=1 To Temp_Str
Test_Str=(Mid(Str,I,1))
Strleft=Strleft&Test_Str
If Asc(Test_Str)>0 Then
lens=lens+1
Else
lens=lens+2
End If
If lens>=L Then Exit For
Next
End Function
Function Strright(Str,L)
Temp_Str=Len(Str)
For i = Temp_Str to 1 step -1
Test_Str=(Mid(Str,I,1))
Strright=Test_Str&Strright
If Asc(Test_Str)>0 Then
lens=lens+1
Else
lens=lens+2
End If
If lens>=L Then Exit For
Next
End Function
也有注意的地方,如果用在循環(huán)中,因不變量“i”也是常用于循環(huán)的變量,執(zhí)行以下函數(shù)時,“i”的值會發(fā)生變化,如果是調(diào)用他的循環(huán)中用到相同的變量,會產(chǎn)生未知的結(jié)果,請換用其它變量名。
以下用法和len(),left(),right()一樣。
程序代碼
復(fù)制代碼 代碼如下:
Function Strlength(Str)
Temp_Str=Len(Str)
For I=1 To Temp_Str
Test_Str=(Mid(Str,I,1))
If Asc(Test_Str)>0 Then
Strlength=Strlength+1
Else
Strlength=Strlength+2
End If
Next
End Function
Function Strleft(Str,L)
Temp_Str=Len(Str)
For I=1 To Temp_Str
Test_Str=(Mid(Str,I,1))
Strleft=Strleft&Test_Str
If Asc(Test_Str)>0 Then
lens=lens+1
Else
lens=lens+2
End If
If lens>=L Then Exit For
Next
End Function
Function Strright(Str,L)
Temp_Str=Len(Str)
For i = Temp_Str to 1 step -1
Test_Str=(Mid(Str,I,1))
Strright=Test_Str&Strright
If Asc(Test_Str)>0 Then
lens=lens+1
Else
lens=lens+2
End If
If lens>=L Then Exit For
Next
End Function
您可能感興趣的文章:
相關(guān)文章
使用AJAX實現(xiàn)UTF8編碼表單提交到GBK編碼腳本無亂碼的解決方法
這篇文章主要介紹了用AJAX實現(xiàn),多個不同編碼的項目(GBK,UTF8)互相通過 POST/GET 匯總表單數(shù)據(jù)。最終實現(xiàn) 使用同一個頁面接收 不同編碼的 表單(GBK,UTF8),特別適合 JS 采集項目,需要的朋友可以參考下2020-09-09實現(xiàn)UTF8轉(zhuǎn)換GB2312國標(biāo)碼的asp代碼
ASP來實現(xiàn)UTF8轉(zhuǎn)換GB2312國標(biāo)碼-GB2312轉(zhuǎn)UTF-8,需要的朋友可以參考下。2010-04-04ASP中解決“對象關(guān)閉時,不允許操作。”的詭異問題……
本文解決ASP中“對象關(guān)閉時,不允許操作?!钡脑幃悊栴},找到問題的根本,才能真正意義上解決,供大家參考了。2016-03-03非常不錯的列出sql服務(wù)器上所有數(shù)據(jù)庫的asp代碼
非常不錯的列出sql服務(wù)器上所有數(shù)據(jù)庫的asp代碼...2006-12-12解決 JScript 中使用日期類型數(shù)據(jù)時出現(xiàn)類型錯誤的問題
在服務(wù)端JScript中,有些時候需要使用日期類型的數(shù)據(jù),比如說設(shè)置一個cookie的到期時間,更新數(shù)據(jù)庫中的日期字段等。但是按照平常的方法來用js里的date類型數(shù)據(jù)時,運行時就會發(fā)生錯誤。2008-05-05