UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> RemSpecial    

Contents

RemSpecial() Function

Removes all special characters from a string.

Syntax

CODE
RemSpecial(strText [, exception1][, exception2][, exception]...)

Where "strText" the text you want to strip the special characters from; exception1..N are optional characters that are considered not "special".

CODE

Public Function RemSpecial(strText As String, ParamArray strExceptions()) As String
'Removes special characters from a string.
'
' http://www.utteraccess.com/wiki/index.php/RoundToNearest
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
'
' You are free to use this code in any application,
' provided this notice is left unchanged.
'
' rev  date        brief descripton
' 1.0  2013-03-11  Initial Release
'
'Usage:
'RemSpecial("My // text here") --> Yeilds: "Mytexthere"
'RemSpecial("My // text here", " ") --> Yeilds: "My text here"
'RemSpecial("My //\\ text here","\", " ") --> Yeilds: "My \\ text here"
   
   Dim x As Integer
   Dim y As Integer
   Dim strX As String
   Dim strStrippedText As String
   
   'Ascii codes
   Const conNumberRangeStart = 48
   Const conNumberRangeStop = 57
   Const conCapLettersStart = 65
   Const conCapLettersStop = 90
   Const conSmallLettersStart = 97
   Const conSmallLettersStop = 122
       
   'Loop through each digit of the string to determine if it falls into the
   'Ascii ranges OR is an exception
   For x = 1 To Len(strText)
   
       strX = Mid(strText, x, 1)
       
       Select Case Asc(strX)
       
           Case conNumberRangeStart To conNumberRangeStop, _
                conCapLettersStart To conCapLettersStop, _
                conSmallLettersStart To conSmallLettersStop
               
               strStrippedText = strStrippedText & strX
       
           Case Else
           
               For y = 0 To UBound(strExceptions())
                   If strX = strExceptions(y) Then
                       strStrippedText = strStrippedText & strX
                   End If
               Next y
               
       End Select
   Next x
   
   RemSpecial = strStrippedText
   
End Function

Return Value

String.

Example

From the Immediate Window:

CODE

? RemSpecial("[censored]&o"
Hello

? RemSpecial("Hello.")
Hello

? RemSpecial("Hello&.*^%$", ".", "&")
Hello&.

? RemSpecial("Hello World")
HelloWorld

? RemSpecial("Hello World!", " ")
Hello World

See Also

fStripIllegal()


Creative Commons License
RemSpecial by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 1,725 times.  This page was last modified 05:51, 23 May 2014 by Brent Spaulding.   Disclaimers