Last active
May 3, 2020 03:08
-
-
Save gwobcke/fed8e66efb80a8a460c563d98ac87604 to your computer and use it in GitHub Desktop.
A simple collection of string functions in Classic ASP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
'////////////////////////////////////////////////// | |
'// | |
'// | |
'// | |
'////////////////////////////////////////////////// | |
Function MixedCase(strInput) | |
Dim strPos, strSpace, strOutput | |
strPosition = 1 | |
'//Loop through the string looking for space characters | |
Do While InStr(strPosition, strInput, " ", 1) <> 0 | |
strSpace = InStr(strPosition, strInput, " ", 1) | |
strOutput = strOutput & UCase(Mid(strInput, strPosition, 1)) & LCase(Mid(strInput, strPosition+1, strSpace-strPosition)) | |
strPosition = strSpace+1 | |
Loop | |
'//Last word is currently uncapitalized - fix this | |
MixedCase = strOutput & UCase(Mid(strInput, strPosition, 1)) & LCase(Mid(strInput, strPosition + 1)) | |
End Function | |
'////////////////////////////////////////////////// | |
'// | |
'// | |
'// | |
'////////////////////////////////////////////////// | |
Function StripSpecialChar(strInput) | |
Dim objRegExp | |
Set objRegExp = New Regexp | |
objRegExp.IgnoreCase = True | |
objRegExp.Global = True | |
objRegExp.Pattern = "[\+\#\@\&\%\$\?\*]" | |
'//Replace all character matches with an Empty String | |
StripSpecialChar = objRegExp.Replace(strInput, "") | |
Set objRegExp = Nothing | |
End Function | |
'////////////////////////////////////////////////// | |
'// ZeroPad(int, int) | |
'// this function could easily be re-used for other purposes such as product ID numbering like "0013" etc. | |
'// here it's used to zero pad a month number | |
'////////////////////////////////////////////////// | |
FUNCTION ZeroPad(thisNumber, padLength) | |
ZeroPad = String(padLength - LEN(thisNumber), "0") & thisNumber | |
END FUNCTION | |
DIM paddedMonth, thisMonth, padLength | |
thisMonth = Month(Now()) | |
padLength = 2 | |
paddedMonth = ZeroPad(thisMonth, padLength) | |
'////////////////////////////////////////////////// | |
'// if Now() was 23/1/2018 -- paddedMonth would hold "01" as a string while thisMonth would be numeric 1 | |
'// if Now() was 10/11/2017 -- paddedMonth would hold "10" as a string while thisMonth would be numeric 10 | |
'////////////////////////////////////////////////// | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment