A string processing class (VBScript) in ASP

zhaozj2021-02-16  57

This class is used to handle strings, is old-written, I added the features and parameters inside.

Instructions:

=============== Test.asp ============================================================

<% DIM STRSET STR = New StringOperations Test = Str.ToChararray ("Check this out") response.write " str.tochararray :" for i = 0 to Ubound (test) response.write test i) & "" next response.write "

" test1 = str.arrayToString (test) response.write " str.arrayToString :" & test1 response.write "

"response.write" str.startsWith : "& str.startsWith (test1," ch ") response.write"

"response.write" str .endWith : "& str.endsWith (test1," out ") response.write"

"response.write" str.clone : "& str.clone ( "abc", 10) response.write "

" response.write " str.trimStart :" & str.trimStart (test1, 3) response.write "

"response.write" str.trimEnd : "& str.trimEnd (test1, 2) response.write"

"response.write" str.swapCase : "& str.swapCase (" hiHiHi ") response.write"

"response.write" str.isAlphabetic : "& str.isAlphabetic ("! ") response.write"

"response.write" str.capitalize : "& str.capitalize (" clara fehler ") Set str = Nothing%>

=============== StringOperations.asp ================ <% Class StringOperations

'********************************************************** ************************************ '@ function description: Turn the character to a CHAR type array' '@ parameter description: - STR [ String '' @ return value: - [array] char type array '*********************************** *************************************************************************** PUBLIC FUNCTION Tochararray (byval Str) Redim Charray (LEN (STR) for i = 1 to Len (STR) Chararray (i-1) = MID (Str, I, 1) Next TocharRay = Chararray End Function '****** *********************************************************** *********************** * Function Description: Convert an array into a string '' @ parameter description: - Arr [array]: data that needs to be converted '' @ Return Value: - [String] String '************************************************* *********************************************** Public Function ArrayTString (Byval Arr) for i = 0 TO Ubound (arr) strobj = strobj & arr (i) Next ArrayTString = STROBJ End Function '************************************************* ********************************************** '' @Features Description: Check the source string STR to start with Chars' '@ parameter description: - Str [string]: source string' '@ parameter description: - Chars [string]: compare character / string' @ return value: - [BOOL] '********** *********************************************************** **************** PUBLIC FUNCTION STARTSWITH (Byval Str, Chars) = chars damwith = true else startswith = false end if End function ' *********************************************************** *********************************** '' @ function description: Check the source string STR whether the end '' @ parameter description: - STR [ String]: Source string '' @ parameter description: - Chars [string]: compare character / string '' @ return value: - [bool] '

*********************************************************** ********************************** PUBLIC FUNCTION Endswith (Byval Str, Chars) IF Right (STR, LEN (Chars) = Chars Ten endswith = True else endswith = false end if End Function '***************************************************************************************************************************** *********************************** The '@ function description: copy n string str' ' @ Parameter Description: - Str [string]: Source string '' @ parameter description: - n [int]: copy number '' @ return value: - [String] Reproduced string '******* *********************************************************** ************************** PUBLIC FUNCTION Clone (byval str, n) for i = 1 to n value = value & str next clone = value end function '**** *********************************************************** ****************************** '' @ function description: Delete the source string STR '' '@ parameter description: - Str [string]: Source string '' @ parameter description: - n [int]: Deleted characters number '' @ return value: - [String] Deleted string '************* *********************************************************** ************ Public Function Trimstart (Byval Str, N) Value = MID (STR, N 1) Trimstart = Value End Function '************ ****************** ********************************************** '' @Features Description: Delete the last n string '' @ parameter description: - str [string]: source string '' @ parameter description: - n [int]: Deleted characters' number '' @ return value : - [String] Deleted string '*********************************************************** ********************************************** Public Function Trimend (byval str, n) value = left STR, LEN (STR) -N) Trimend = value end function '******************************************* *************************************************** * Function Description: Check Character Character Whether it is English character az or az '' @ parameter description: - Character [char]: Check the character '

'@ Return Value: - [Bool] If it is English characters, return TRUE, vice versa 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: Size conversion to the STR string' '@ parameter description: - Str [string ]: Source string '' @ Return value: - [String] String after conversion '************************************** ************************************************************************* 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: Convert the first letter of each word in the source string STR to uppercase '' @ parameter description: - str [string]: Source string '' @ return value: - [String] String after conversion '************************************************** *********************************** Public Function Capitalize (STR) Words = Split (STR, "" ) For i = 0 to Ubound (Words) if not i = 0 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 functionend class%>>>>>>>>> "" "" "" "" "" "" "" "" ") - 1) WORDS = ARRAYTOSTRING (WORDS) End Functionend Class%>

转载请注明原文地址:https://www.9cbs.com/read-24033.html

New Post(0)