Public Function CheckNReplace(ByVal strInput As String, _
                    ByVal strBlackList As String, _
                    Optional ByVal strWhiteList As String) As String
'
' arnel gp
'
' purpose to replace Blacklisted chars with Whitelist one
'
' example:
'
' debug.print CheckNReplace("arne%#puzon","%#","l ")
'
' this means on the input string, "arne%#puzon"
' "%" will be replaced with "l"
' "#" will be replaced with space " "
'
' so, there must be a 1 to 1 find string and replacement string
'
' if strWhiteList length is less than the length of Blacklist
' it is asssumed that Blacklisted char not in Whitelist will
' be replaced by a space char.
    Dim lngPos As Long
    Dim lngLen As Long
    Dim strMid As String
    Dim lngInstr As Long
    ' get the length of the input string
    lngLen = Len(strInput)
    ' loop up to the length of the string
    For lngPos = 1 To lngLen
        ' get one character from the input string
        strMid = Mid(strInput, lngPos, 1)
        ' compare if this is in BLOCKED characterlist
        lngInstr = InStr(1, strBlackList, strMid, vbTextCompare)
        ' if it is in blacklist, substitute another string from strReplacement
        If lngInstr <> 0 Then
            ' if there is available replacement, meaning
            ' the length of strReplacement is shorter than
            ' lnginstr then substitute space (" ")
            strInput = Left(strInput, lngPos - 1) & _
                    IIf(Len(strWhiteList) < lngInstr, " ", Mid(strWhiteList, lngInstr, 1)) & _
                    Mid(strInput, lngPos + 1)
        End If
    Next
    CheckNReplace = strInput
End Function