Remove Character Function

This is a useful function to remove characters from a string, in the code below you will see a crafty usage of the function just to give the numbers in the string. Rather than having a long string of all possible characters first I use the function to create a variable of the string without the numbers, this is then used as the remove parameter of the function used along with the original string it returns just the numbers from the string.

Code:
<%
Function RemChr(string, remove)
    Dim i, j, tmp, strOutput
    strOutput = ""
    for j = 1 to len(string)
        tmp = Mid(string, j, 1)
        for i = 1 to len(remove)
            tmp = replace( tmp, Mid(remove, i, 1), "")
            if len(tmp) = 0 then exit for
        next
        strOutput = strOutput & tmp
    next
    RemChr = strOutput
End Function

' First remove numbers from string
chrToRemove = remchr("$10,000 max. amount paid","0123456789")
' then use new string as characters to remove
response.write remchr("$10,000 max. amount paid",chrToRemove) & "<br />"

chrToRemove = remchr("$10,000","0123456789")
Response.Write remchr("$10,000",chrToRemove)
%>

The function has two parameters the first is the string you want to remove the characters from and the second is the characters you want to remove, for example...

string = remChr("Today's total stock value is £15,477.00", "Today's total stock value is £")

Will remove the text just leaving the stock value but as it is a remove character function setting the second parameter to "Today'stlckvuei£ " would remove all the text as you only need to specify each character once.

Remove Character Function Test
     
 
 
Results: