PDA

View Full Version : Solved: Remove commas and spaces in the middle of a string



KennyJ
05-28-2008, 04:35 AM
I have a bunch of strings with commas and spaces in the middle of them and i need to remove the commas and spaces and replace them with a "-". The comma will not always be in the same place and sometimes there may be spaces on both sides of the comma but my goal is to make the string go from eg. "abc, 123" to "abc-123" or "abc , 123" to "abc-123" or "abc ,123" to "abc-123" the string will not always be the same length either. Thanks

JimmyTheHand
05-28-2008, 04:54 AM
Function RemoveThings(sParam As String) As String
Dim Result As String
Result = sParam
Do
Result = Replace(Result, " ", "-")
Result = Replace(Result, ",", "-")
Result = Replace(Result, "--", "-")
Loop Until InStr(Result, "--") = 0
RemoveThings = Result
End Function


This should work with a string of any length, with commas and spaces of any number, in any position.

HTH
Jimmy

KennyJ
05-28-2008, 05:15 AM
Works Perfect Thank You!