This class is used to process strings and is written by foreigners. I have added descriptions of the functions and parameters in it.
Usage:
================== Test. asp =============================
<! -- # Include file = "stringoperations. asp" -->
<%
Dim Str
Set STR = new stringoperations
Test = Str. tochararray ("Check this out ")
Response. Write "<strong> Str. tochararray </strong> :"
For I = 0 to ubound (test)
Response. Write test (I )&""
Next
Response. Write "<br>"
Test1 = Str. arraytostring (test)
Response. Write "<strong> Str. arraytostring </strong>:" & test1
Response. Write "<br>"
Response. Write "<strong> Str. startswith </strong>:" & Str. startswith (test1, "ch ")
Response. Write "<br>"
Response. Write "<strong> Str. endwith </strong>:" & Str. endswith (test1, "out ")
Response. Write "<br>"
Response. Write "<strong> Str. Clone </strong>:" & Str. Clone ("ABC", 10)
Response. Write "<br>"
Response. Write "<strong> Str. trimstart </strong>:" & Str. trimstart (test1, 3)
Response. Write "<br>"
Response. Write "<strong> Str. trimend </strong>:" & Str. trimend (test1, 2)
Response. Write "<br>"
Response. Write "<strong> Str. swapcase </strong>:" & Str. swapcase ("hihihi ")
Response. Write "<br>"
Response. Write "<strong> Str. isalphabetic </strong>:" & Str. isalphabetic ("! ")
Response. Write "<br>"
Response. Write "<strong> Str. capitalize </strong>:" & Str. capitalize ("Clara fehler ")
Set STR = nothing
%>
================== Stringoperations. asp ==============================
<%
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
End Class
%>