Created
November 29, 2012 03:10
-
-
Save hiscaler/4166543 to your computer and use it in GitHub Desktop.
ASP String operation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
' String helper | |
Class Class_StringHelper | |
'************************************************** | |
'函数名:strLength | |
'作 用:检测字符串长度 | |
'************************************************** | |
Function strLength(Str) | |
dim i, Temp_str, Test_Str, size | |
size = 0 | |
Temp_Str = Len(Str) | |
For i = 1 To Temp_Str | |
Test_Str = Mid(Str, i, 1) | |
If Asc(Test_Str) > 0 Then | |
size = size + 1 | |
Else | |
size = size + 2 | |
End If | |
Next | |
strLength = size | |
End Function | |
'************************************************** | |
'函数名:strlen | |
'作 用:剪切字符串 | |
'参 数: str要剪切的串,lennum 剪切长度 | |
'************************************************** | |
Function cutStr(str, lennum, suffix) | |
If strLength(str) <= lennum Then | |
cutStr = str | |
Else | |
If (UtilHelper.checkNull(suffix)) Then | |
suffix = "..." | |
End If | |
Dim p_num, i, x, temp | |
p_num = 0 | |
x = 0 | |
Do While Not p_num > lennum | |
x = x + 1 | |
If Asc(Mid(str, x, 1)) < 2 Then | |
p_num = Int(p_num) + 2 | |
Else | |
p_num = Int(p_num) + 1 | |
End If | |
Loop | |
cutStr = left(trim(str), p_num) + suffix | |
End If | |
End Function | |
' 保持以指定字符分割的字符串的唯一性 | |
Public Function stringUnique(ByVal str, ByVal delimiter, ByVal removeEmpty) | |
If (UtilHelper.checkNull(str) OR UtilHelper.checkNull(delimiter)) Then | |
stringUnique = "" | |
Else | |
If (removeEmpty) Then | |
stringUnique = UtilHelper.array2string(ArrayHelper.removeArrayEmpty(ArrayHelper.arrayUnique(UtilHelper.string2array(str, delimiter))), delimiter) | |
Else | |
stringUnique = UtilHelper.array2string(ArrayHelper.arrayUnique(UtilHelper.string2array(str, delimiter)), delimiter) | |
End If | |
End If | |
End Function | |
End Class | |
dim StringHelper | |
set StringHelper = new Class_StringHelper | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment