UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> ReplaceRE    


Replace whole word(s) text in a sting with other whole word(s). Example

  strText = "This is an old one."
  strFind = "an old one"
  strReplace = "a new one"
  result = ReplaceRE(strText,strFind,strReplace)
  debug.print result 'prints "This is a new one."
' ReplaceRE
' http://www.utteraccess.com/wiki/ReplaceRE
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
' You are free to use this code in any application,
' provided this notice is left unchanged.
' rev  date                          brief descripton
' 1.0  2015-10-15                    
'  replace text in a string with other text along word boundaries
'  strText - string in which we are replacing text
'  strFind - the string being replaced
'  strReplace - the string with which strFind is being replaced
'  a string in which strFind has been replaced with strReplace
'  The replacements are along word boundaries, meaning we are only dealing
'     with whole words.
Function ReplaceRE(ByVal strText As String, strFind As String, strReplace As String)
  Dim RE As Object
  Dim temp As String
  temp = strText
  'Set RE = New RegExp
  Set RE = CreateObject("VBScript.RegExp")
  With RE
     .IgnoreCase = True
     .Global = True
     .MultiLine = True
     .Pattern = "\b" & strFind & "\b"
     temp = .Replace(temp, strReplace)
  End With
  ReplaceRE = temp
End Function

Creative Commons License
ReplaceRE by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search

Thank you for your support!
This page has been accessed 1,697 times.  This page was last modified 14:03, 15 October 2015 by azolder.   Disclaimers