Skip to content

Instantly share code, notes, and snippets.

@gwobcke
Last active May 3, 2020 03:08
Show Gist options
  • Save gwobcke/fed8e66efb80a8a460c563d98ac87604 to your computer and use it in GitHub Desktop.
Save gwobcke/fed8e66efb80a8a460c563d98ac87604 to your computer and use it in GitHub Desktop.
A simple collection of string functions in Classic ASP
<%
'//////////////////////////////////////////////////
'//
'//
'//
'//////////////////////////////////////////////////
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