VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A simple routine to remove all non-alphanumeric charaters from a string (Quickly!).

by Rob Robinson (1 Submission)
Category: String Manipulation
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Wed 13th September 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

A simple routine to remove all non-alphanumeric charaters from a string (Quickly!).

Rate A simple routine to remove all non-alphanumeric charaters from a string (Quickly!).



'*****************************************************************
'Description:   This routine will remove any non-alphanumeric
'               characters from the Words.
'Pass:          Words       - Keywords to clean
'Return:        CleanWords  - Final clean string
'Raise Errors:
'-----------------------------------------------------------------
'Date     Devoloper           Comments
'9/1/00   R. Robinson         Initial Design
'
'*****************************************************************

    Const ALPHA = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz "
    Const SNG_SPACE = " "
    Const DBL_SPACE = "  "
    
    Dim iPos As Integer
    Dim sChar As String, sWork As String
    Dim lCntr As Long
    
    'Set the working variable
    sWork = Trim(Words)
    
    'Remove all charaters that are NOT in the ALPHA const
    For lCntr = 0 To 255
        If InStr(ALPHA, Chr(lCntr)) = 0 Then
            sWork = Replace(sWork, Chr(lCntr), SNG_SPACE)
        End If
    Next lCntr
    
    'Remove all double spaces created
    iPos = InStr(sWork, DBL_SPACE)
    While iPos > 0
        sWork = Replace(sWork, DBL_SPACE, SNG_SPACE)
        iPos = InStr(sWork, DBL_SPACE)
    Wend
    
    'Return the cleaned string
    CleanWords = sWork
    
End Function


Download this snippet    Add to My Saved Code

A simple routine to remove all non-alphanumeric charaters from a string (Quickly!). Comments

No comments have been posted about A simple routine to remove all non-alphanumeric charaters from a string (Quickly!).. Why not be the first to post a comment about A simple routine to remove all non-alphanumeric charaters from a string (Quickly!)..

Post your comment

Subject:
Message:
0/1000 characters