UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> FixText Letters    


This function uses the Replace() function to remove characters that are not alphabetic letters from the input string.

Related Functions: Strip_Unwanted_Characters FixText_Digits

' FixText Letters
' http://sbp.ghubbell.com/wiki/FixText_Letters
' 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_Letters(strInput As String) As String
'Purpose    : Remove all characters from input string that are non-alpha
'Author     : UA Wiki
'Description: loops through the input string replacing non-alphas with
'             placeholder character then replaces the placeholder
'             with empty string character. The placeholder is used so
'             that the result string length does not change until
'             all characters have been inspected
'Useage     : strOutput = FixText_Letters(strInput)
'Date       : 04Jul16
   Const cstrEMPTY = ""            'empty string
   Const cstrPLACEHOLDER = ":"     'temporary placeholder
                                   ' colon used here - bar character is
                                   ' probably better

   Dim strResult As String     'string to hold result
   Dim strChar As String       'string to hold current character

   Dim intCounter As Integer   'counter used to control loop

   On Error GoTo HandleError
   'initialize result string
   strResult = strInput
   'loop throught result string
   For intCounter = 1 To Len(strResult)
       strChar = (Mid(strResult, intCounter, 1))
       'replace non-letter with placeholder
       If (Asc(strChar) < Asc("a") _
           Or Asc(strChar) > Asc("z")) _
           And (Asc(strChar) < Asc("A") _
                Or Asc(strChar) > Asc("Z")) Then
           strResult = Replace(strResult, strChar, cstrPLACEHOLDER)
       End If
   Next intCounter

   'replace the placeholder with empty string
   strResult = Replace(strResult, cstrPLACEHOLDER, cstrEMPTY)
   'return the fixed string

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

End Function

Creative Commons License
FixText Letters 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 2,029 times.  This page was last modified 16:08, 4 July 2016 by Glenn Lloyd.   Disclaimers