Copy codeThe Code is as follows: <%
Class StringOperations
''************************************** **************************************
'''' @ Function Description: replace a string with a char array.
''' @ Parameter description:-str [string]: string to be converted
''' @ Return value:-[Array] Char Array
''************************************** **************************************
Public function toCharArray (byVal str)
Redim charArray (len (str ))
For I = 1 to len (str)
CharArray (I-1) = Mid (str, I, 1)
Next
ToCharArray = charArray
End function
''************************************** **************************************
'''' @ Function Description: converts an array into a string.
''' @ Parameter description:-arr [Array]: Data to be converted
''' @ Return value:-[string] string
''************************************** **************************************
Public function arrayToString (byVal arr)
For I = 0 to UBound (arr)
StrObj = strObj & arr (I)
Next
ArrayToString = strObj
End function
''************************************** **************************************
''' @ Function Description: checks whether the source string str starts with chars.
''' @ Parameter description:-str [string]: Source string
''' @ Parameter description:-chars [string]: Comparison character/string
''' @ Return value:-[bool]
''************************************** **************************************
Public function startsWith (byVal str, chars)
If Left (str, len (chars) = chars then
StartsWith = true
Else
StartsWith = false
End if
End function
''************************************** **************************************
''' @ Function Description: checks whether the source string str ends with chars.
''' @ Parameter description:-str [string]: Source string
''' @ Parameter description:-chars [string]: Comparison character/string
''' @ Return value:-[bool]
''************************************** **************************************
Public function endsWith (byVal str, chars)
If Right (str, len (chars) = chars then
EndsWith = true
Else
EndsWith = false
End if
End function
''************************************** **************************************
'''' @ Function Description: Copy N strings to str
''' @ Parameter description:-str [string]: Source string
''' @ Parameter description:-n [int]: Number of copies
''' @ Return value:-[string] copied string
''************************************** **************************************
Public function clone (byVal str, n)
For I = 1 to n
Value = value & str
Next
Clone = value
End function
''************************************** **************************************
''' @ Function Description: deletes the first N characters of the source string 'str '.
''' @ Parameter description:-str [string]: Source string
''' @ Parameter description:-n [int]: number of characters deleted
''' @ Return value:-[string] The deleted string
''************************************** **************************************
Public function trimStart (byVal str, n)
Value = Mid (str, n + 1)
TrimStart = value
End function
''************************************** **************************************
''' @ Function Description: deletes the last N strings of the source string 'str '.
''' @ Parameter description:-str [string]: Source string
''' @ Parameter description:-n [int]: number of characters deleted
''' @ Return value:-[string] The deleted string
''************************************** **************************************
Public function trimEnd (byVal str, n)
Value = Left (str, len (str)-n)
TrimEnd = value
End function
''************************************** **************************************
''' @ Function Description: checks whether the character is an English character A-Z or a-z.
''' @ Parameter description:-character [char]: Check character
''' @ Return value:-[bool] if it is an English character, TRUE is returned. Otherwise, FALSE is returned.
''************************************** **************************************
Public function isAlphabetic (byVal character)
AsciiValue = cint (asc (character ))
If (65 <= asciiValue and asciiValue <= 90) or (97 <= asciiValue and asciiValue <= 122) then
IsAlphabetic = true
Else
IsAlphabetic = false
End if
End function
''************************************** **************************************
'''' @ Function Description: converts the case of str strings.
''' @ Parameter description:-str [string]: Source string
''' @ Return value:-[string] converted string
''************************************** **************************************
Public function swapCase (str)
For I = 1 to len (str)
Current = mid (str, I, 1)
If isAlphabetic (current) then
High = asc (ucase (current ))
Low = asc (lcase (current ))
Sum = high + low
Return = return & chr (sum-asc (current ))
Else
Return = return & current
End if
Next
SwapCase = return
End function
''************************************** **************************************
'''' @ Function Description: converts the first letter of each word in the source string str to uppercase.
''' @ Parameter description:-str [string]: Source string
''' @ Return value:-[string] converted string
''************************************** **************************************
Public function capitalize (str)
Words = split (str ,"")
For I = 0 to ubound (words)
If not I = 0 then
Tmp = ""
End if
Tmp = tmp & ucase (left (words (I), 1) & right (words (I), len (words (I)-1)
Words (I) = tmp
Next
Capitalize = arrayToString (words)
End function
''************************************** **************************************
''' @ Function Description: Filter ''after the source character 'str' ''''
''' @ Parameter description:-str [string]: Source string
''' @ Return value:-[string] converted string
''************************************** **************************************
Public function checkstr (Str)
If Trim (Str) = "" Or IsNull (str) Then
Checkstr = ""
Else
Checkstr = Replace (Trim (Str ),"''","''''")
End if
End function
''************************************** **************************************
'''' @ Function Description: filter the HTML code in the str string.
''' @ Parameter description:-str [string]: Source string
''' @ Return value:-[string] converted string
''************************************** **************************************
Public Function HtmlEncode (str)
If Trim (Str) = "" Or IsNull (str) then
HtmlEncode = ""
Else
Str = Replace (str, ">", "> ")
Str = Replace (str, "<", "<")
Str = Replace (str, Chr (32 ),"")
Str = Replace (str, Chr (9 ),"")
Str = Replace (str, Chr (34 ),""")
Str = Replace (str, Chr (39 ),"'")
Str = Replace (str, Chr (13 ),"")
Str = Replace (str, Chr (10) & Chr (10), "</p> <p> ")
Str = Replace (str, Chr (10), "<br> ")
HtmlEncode = str
End if
End Function
''************************************** **************************************
'''' @ Function Description: Calculate the length of the source string Str (two Chinese characters in length)
''' @ Parameter description:-str [string]: Source string
''' @ Return value:-[Int] length of the source string
''************************************** **************************************
Public Function strLen (Str)
If Trim (Str) = "" Or IsNull (str) Then
Strlen = 0
Else
Dim P_len, x
P_len = 0
StrLen = 0
P_len = Len (Trim (Str ))
For x = 1 To P_len
If Asc (Mid (Str, x, 1) <0 Then
StrLen = Int (StrLen) + 2
Else
StrLen = Int (StrLen) + 1
End If
Next
End if
End Function
''************************************** **************************************
'''' @ Function Description: truncates the first LenNum characters of the source string Str (one Chinese character is 2 bytes long)
''' @ Parameter description:-str [string]: Source string
''' @ Parameter description:-LenNum [int]: the length of the clip.
''' @ Return value:-[string]: converted string
''************************************** **************************************
Public Function CutStr (Str, LenNum)
Dim P_num
Dim I, X
If StrLen (Str) <= LenNum Then
Cutstr = Str
Else
P_num = 0
X = 0
Do While Not P_num> LenNum-2
X = X + 1
If Asc (Mid (Str, X, 1) <0 Then
P_num = Int (P_num) + 2
Else
P_num = Int (P_num) + 1
End If
Cutstr = Left (Trim (Str), X )&"..."
Loop
End If
End Function
End class
%>