Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove punctuation, spaces from string

Status
Not open for further replies.

mulligh

Technical User
May 8, 2001
97
0
0
US
Hi- I need to remove all spaces and punctuation from a string. What function do I need to use?

For example:

Trees. Blue Spruce
Trees, Large. Redwood

Output:

TreesBlueSpruce
TreesLargeRedwood

Thanks for your assistance!

 
If you are using Office 2003 have a look at the replace function. If not (I'm not sure whether it's in Office XP or not) post back and I'll post an example of how to implement your own replace function.

Ed Metcalfe.

Please do not feed the trolls.....
 
Code:
Private Sub CommandButton1_Click()
   MsgBox Remove_Punctuation_Spaces(" . Trees. Blue Spruce")
   MsgBox Remove_Punctuation_Spaces("Trees , Large.Redwood")
   MsgBox Remove_Punctuation_Spaces("Trees , Large.Redwood! ")
   MsgBox Remove_Punctuation_Spaces("Trees , Large.Redwood ? ")
End Sub

Private Function Remove_Punctuation_Spaces(aline As String) As String
   Dim regex As Object

   Set regex = CreateObject("VBScript.RegExp")
   regex.Global = True
   regex.pattern = "[^0-9A-Za-z]"   Remove_Punctuation_Spaces = regex.Replace(aline, "")
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top