More ASP String Functions
February 10th, 2007
Comments Off
Continuing my previous post with ASP string functions, here are a few more code snippets
The first code snippet is a little function that strips out specified special characters. It basically seeks out any of the characters that exist in the array and removes them all.
<%
Function StripSpecialChar(inStr)
dim sOut,outStr,arrSpecialChar,intCounter
arrSpecialChar = Array("%20","&","&","#","+","@")
outStr = inStr
intCounter = 0
Do Until intCounter = UBOUND(arrSpecialChar)+1
sOut = replace(outStr,arrSpecialChar(intCounter) ,"")
intCounter = intCounter + 1
outStr = sOut
Loop
StripSpecialChar = outStr
end Function
%>
The final snippet is a simple function that will check an array for any occurances of a particular string.
<%
Function in_array(element, arr)
For i=0 To Ubound(arr)
If Trim(arr(i)) = Trim(element) Then
in_array = True
Exit Function
Else
in_array = False
End If
Next
End Function
str = "Apple"
colors = Array("Banana","Apple","Orange")
If in_array(str,colors) Then Response.Write str & " is in the array"
Else Response.Write str & " is not in the array"
End If
%>
I hope you find these functions as useful as I do.