On this basis, this article adds some functions that are suitable for Chinese websites. Some functions may not be added yet. If you are interested, you can add a function on this basis, but don't forget to share it!
<%
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: Check 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: Check 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: Check whether the character is an English character A-Z or a-z
''@ Parameter description:-character [char]: Check character
''@ Return value:-[bool] returns true if it is an English character; otherwise, false.
'*************************************** *************************************
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 the 'from 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, ">", "& gt ;")
STR = Replace (STR, "<", "& lt ;")
STR = Replace (STR, CHR (32), "& nbsp ;")
STR = Replace (STR, CHR (9), "& nbsp ;")
STR = Replace (STR, CHR (34), "& quot ;")
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 Truncation length.
''@ 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
%>