UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> Strip Unwanted Characters    


This function uses the Replace() function to remove characters from the input string that might otherwise cause problems with filtering or storage of the text. The caller can specify the character that will replace the problem character. If no replacement is specified the problem character is simply removed from the result (replaced with the empty string ""

Related Functions: FixText_Digits FixText_Letters

' Strip Unwanted Characters
' http://www.utteraccess.com/wiki/Strip_Unwanted_Characters
' 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  2016-07-04                    Replacing unwanted characters
Public Function FixText(strText As String, Optional strReplace As String = "") As String
'Purpose    : remove extraneous characters from a text string
'Author     : UA Wiki
'Description: removes non-alpha or other 'illegal'characters
'             from the input string, replacing them with
'             the empty string character or character specfied
'             in the strReplace argument
'             to facilitate, for example, filtering names that
'             may include non-alphabetic characters
'Useage     : strOutput = FixText(strInput)
'Date       : 04Jul16

'edit this constant to include all characters you want to eliminate
   Const cstrFIXCHARS = " '-_/\"

   Dim strResult As String     'string to hold result
   Dim intCounter As Integer   'counter used to control loop

   On Error GoTo HandleError

   'initialize result string
   strResult = strText

   'loop once for each character in the fix character string

   For intCounter = 1 To Len(cstrFIXCHARS)
       'replace all instances of unwanted charcter in the result string
       strResult = Replace(strResult, Mid(cstrFIXCHARS, intCounter, 1), strReplace)
   Next intCounter

   'return the fixed string
   FixText = strResult
   Exit Function
   MsgBox Err.Description
   Resume HandleExit
End Function

Creative Commons License
Strip Unwanted Characters 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,913 times.  This page was last modified 15:50, 4 July 2016 by Glenn Lloyd.   Disclaimers