Replace Underscores Between Words from an Object with a Single
Thank you for your help! The Function worked perfectly! Happy New Year.
Tom
"Ron Rosenfeld" wrote:
On Tue, 30 Dec 2008 13:37:34 -0800, TomP
wrote:
I have an object that is filled with many underscores between texts. I
recently got help from your forum on how to remove leading underscores which
works great and now I need help in replacing a line of underscores between
words with a single space.
Thank you again for your help!
============================
Option Explicit
Function ReplaceUnderscore(str As String) As String
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "\s*_+\s*"
ReplaceUnderscore = re.Replace(str, " ")
End Function
==========================
This routine will also replace any spaces that might be before or after the
underscore. so:
Now is________the time -- Now is the time
Now is ____________ the time -- Now is the time
If that is not desired behavior, then change
re.Pattern = "_+"
--ron
|