'String Manipulation - How to Remove two or more hyphens from a string
Sub main()
Dim sText As String
sText = "This test-string. This is -- the test-string. " & _
"This is --------- the test-string. This is - the ------ " & _
"test - string. This is the test--string."
Debug.Print sText
Do While InStr(sText, "--") > 0
sText = Replace(sText, "---", "--")
sText = Replace(sText, "--", "")
sText = Replace(sText, " ", " ")
Loop
Debug.Print sText
End Sub
'Or
Sub main()
'You Need to set reference to Microsoft VBScript Regular Expressions 5.5
Dim sText As String
Dim re As RegExp, m As MatchCollection
Set re = New RegExp
sText = "This test-string. This is -- the test-string. " & _
"This is --------- the test-string. This is - the ------ " & _
"test - string. This is the test--string."
Debug.Print sText
re.Global = True
re.Pattern = "[-]{2,}"
sText = re.Replace(sText, "")
re.Pattern = "[ ]{2,}"
sText = re.Replace(sText, " ")
Debug.Print sText
End Sub
May this will help you...........
