Extrac only the letter part from a text string

  • Thread starter Thread starter Elaine16025
  • Start date Start date
E

Elaine16025

Dear Everyone:

I have a text string field which has all kinds of signs in front of the
letters, some examples are: "---Apples", " 'Pears", "[Bananas]" etc...
How can I get rid of those extra characters and only keep the letters:
"Apples", "Pears", "Bananas"?

Thanks in advance!

Elaine
 
The following untested aircode should remove all non-letters from the word.

Function StripCharacters(InputWord As String) As String
Dim intLoop As Integer
Dim strCurrChar As String
Dim strWorkingString As String

strWorkingString = ""

For intLoop = 1 To Len(InputWord)
strCurrChar = Mid$(InputWord, intLoop, 1)
If (strCurrChar >= "a" And strCurrChar <= "z") _
Or (strCurrChar >= "A" And strCurrChar <= "Z") Then
strWorkingString = strWorkingString & strCurrChar
End If
Next intLoop

StripCharacters = strWorkingString

End Function

Here's an example of using it:

?StripCharacters("--Apple")
Apple
?StripCharacters("[Banana]")
Banana
?StripCharacters("'Pear")
Pear
 
Doug, thank you for you quick response! Your air code works
beautifully! The only problem is that when the string is {apple, red},
it became applered. I will try to see if I can get it fixed.

Elaine
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top