📄 stringoperations.asp
字号:
end function
'**************************************************************************************************************
'' @SDESCRIPTION: Converts an array to a string
'' @PARAM: arr [Array]: the array you want to concat
'' @PARAM: seperator [string]: seperator between the array-fields
'' @RETURN: [string] concated array
'**************************************************************************************************************
public function arrayToString(byVal arr, seperator)
for i = 0 to uBound(arr)
if i > 0 then
strObj = strObj & seperator
end if
strObj = strObj & arr(i)
next
arrayToString = strObj
end function
'******************************************************************************************
'' @SDESCRIPTION: Converts a part of a multidimensional array to a string
'' @PARAM: arr [Array]: the array you want to concat
'' @PARAM: seperator [string]: seperator between the array-fields
'' @PARAM: dimension [int]: the dimension index in the array -> e.g. you have an
'' array of the size (5, 2) -> with dimension 2 you get the array fields
'' (0, 2), (1, 2), ..., (4, 2) as the string object, savvy ?
'' @RETURN: [string] concated array
'******************************************************************************************
public function multiArrayToString(byVal arr, seperator, dimension)
for i = 0 to uBound(arr)
if i > 0 then
strObj = strObj & seperator
end if
strObj = strObj & arr(i, dimension)
next
multiArrayToString = strObj
end function
'**************************************************************************************************************
'' @SDESCRIPTION: Checks if the string begins with ...
'' @PARAM: str [string]: the source string
'' @PARAM: chars [string]: the compare char/string
'' @RETURN: [bool] true if the two strings are equal
'**************************************************************************************************************
public function startsWith(byVal str, chars)
startsWith = (left(str, len(chars)) = chars)
end function
'**************************************************************************************************************
'' @SDESCRIPTION: Checks if the string ends with ...
'' @PARAM: str [string]: the source string
'' @PARAM: chars [string]: the compare char/string
'' @RETURN: [bool] true if the two strings are equal
'**************************************************************************************************************
public function endsWith(byVal str, chars)
endsWith = (right(str, len(chars)) = chars)
end function
'**************************************************************************************************************
'' @SDESCRIPTION: Concats a string "n" times
'' @PARAM: str [string]: the source string
'' @PARAM: n [int]: the number of concats
'' @RETURN: [string] the concated string
'**************************************************************************************************************
public function clone(byVal str, n)
for i = 1 to n : clone = clone & str : next
end function
'**************************************************************************************************************
'' @SDESCRIPTION: Removes characters from the begin of a string
'' @PARAM: str [string]: the source string
'' @PARAM: n [int]: the number of characters you want to remove
'' @RETURN: [string] the trimmed string
'**************************************************************************************************************
public function trimStart(byVal str, n)
value = mid(str, n + 1)
trimStart = value
end function
'**************************************************************************************************************
'' @SDESCRIPTION: Removes characters from the end of a string
'' @PARAM: str [string]: the source string
'' @PARAM: n [int]: the number of characters you want to remove
'' @RETURN: [string] the trimmed string
'**************************************************************************************************************
public function trimEnd(byVal str, n)
value = left(str, len(str) - n)
trimEnd = value
end function
'**************************************************************************************************************
'' @SDESCRIPTION: Removes characters from a given string with all occurencies of a matching string
'' @PARAM: str [string]: the source string
'' @PARAM: stringToTrim [string]: the "find" string which will be trimmed out of the string
'' @RETURN: [string] the trimmed string
'**************************************************************************************************************
public function trimString(byVal str, stringToTrim)
trimString = replace(str, stringToTrim, "", 1, -1)
end function
'**************************************************************************************************************
'' @SDESCRIPTION: Checks if a char is an alphabetic character or not. A-Z or a-z
'' @PARAM: character [char]: The char to check
'' @RETURN: [bool] Wether the char is alphabetic or not.
'**************************************************************************************************************
public function isAlphabetic(byVal character)
asciiValue = cint(asc(character))
isAlphabetic = ((65 <= asciiValue and asciiValue <= 90) or (97 <= asciiValue and asciiValue <= 122))
end function
'**************************************************************************************************************
'' @SDESCRIPTION: Swaps the Case of a String. Lower to Upper and vice a versa
'' @PARAM: str [string]: the source string
'' @RETURN: [string] the swapped 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
'**************************************************************************************************************
'' @SDESCRIPTION: Makes every first letter of every word to upper-case.
'' @DESCRIPTION: Good for Names or cities. Example: "axel schweis" will result in "Axel Schweis"
'' @PARAM: str [string]: the source string
'' @RETURN: [string] changed string
'**************************************************************************************************************
public function capitalize(inputStr)
words = split(inputStr, " ")
for i = 0 to ubound(words)
if not i = 0 then tmp = " "
if len(words(i)) > 0 then tmp = tmp & ucase(left(words(i), 1)) & right(words(i), len(words(i)) - 1)
words(i) = tmp
next
capitalize = arrayToString(words, empty)
end function
'**************************************************************************************************************
'' @SDESCRIPTION: Switches the case of the letters alternatly to U/Lcase - just for fun :)
'' @DESCRIPTION: So "testing" will result in "TeStInG"
'' @PARAM: str [string]: the source string
'' @RETURN: [string] changed string
'**************************************************************************************************************
function leetIt(byVal str)
for i = 1 to len(str)
if i mod 2 = 0 then
leetIt = leetIt & lCase(Mid(str, i, 1))
else
leetIt = leetIt & uCase(Mid(str, i, 1))
end if
next
end function
'**************************************************************************************************************
'' @SDESCRIPTION: Replaces all {n} values in a given string through the n-index field of an array.
'' @DESCRIPTION: Its just like the string.format method in .NET. so if you provide "my Name is {0}" as
'' your input then the {0} will be replaced by the first field of your array. and so on.
'' @PARAM: str [string]: the source string
'' @PARAM: arr [array]: the array with your values
'' @RETURN: [string] changed string
'**************************************************************************************************************
public function format(byVal str, arr)
for i = 0 to ubound(arr)
str = replace(str, "{" & i & "}", cstr(arr(i)))
next
format = str
end function
'**************************************************************************************************************
'' @SDESCRIPTION: Encodes a string into ASCII Characters
'' @DESCRIPTION: This function takes a string (for example an email-address) and converts it to
'' standardized ASCII Character codes, thus blocking bots/spiders from reading your
'' email address, while yet allowing visitors to continue to read and use your proper
'' address via mailto links, etc.
'' @PARAM: str [string]: the string you want to convert
'' @RETURN: [string] the ASCII Encoded String
'' @CREDIT: Teco from Planet Source Code
'**************************************************************************************************************
public function ASCIICode(byval str)
ASCIICode = ""
for i = 1 to len(str)
ASCIICode = ASCIICode & "&#" & asc(mid(str, i, 1)) & ";"
next
end function
end class
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -