Replace Method

Clear Method,Execute Method,Raise Method,Replace Method,Test Method Home home | Other Resources other resources | Advertise with us advertise | Link to us link to us | Contact us contact | Bookmark Us!
Google
 
Where can I find good Windows Web Hosting to host my VBScript Site?
You can find good Windows Hosting which support VBScript, ASP, ASP.Net,VisualStudio.Net and MSSQL at a very reasonable low monthly fee at EasyCGI.com and DiscountASP.Net

Replace Method

Replaces text found in a regular expression search.

object.Replace(string1, string2)

Arguments

object

Required. Always the name of a RegExp object.

string1

Required. String1 is the text string in which the text replacement is to occur.

string2

Required. String2 is the replacement text string.

Remarks

The actual pattern for the text being replaced is set using the Pattern property of the RegExp object.

The Replace method returns a copy of string1 with the text of RegExp.Pattern replaced with string2. If no match is found, a copy of string1 is returned unchanged.

The following code illustrates use of the Replace method.

Function ReplaceTest(patrn, replStr)
  Dim regEx, str1               ' Create variables.
  str1 = "The quick brown fox jumped over the lazy dog."
  Set regEx = New RegExp            ' Create regular expression.
  regEx.Pattern = patrn            ' Set pattern.
  regEx.IgnoreCase = True            ' Make case insensitive.
  ReplaceTest = regEx.Replace(str1, replStr)   ' Make replacement.
End Function

MsgBox(ReplaceTest("fox", "cat"))      ' Replace 'fox' with 'cat'.

In addition, the Replace method can replace subexpressions in the pattern. The following call to the function shown in the previous example swaps each pair of words in the original string:

MsgBox(ReplaceText("(\S+)(\s+)(\S+)", "$3$2$1"))   ' Swap pairs of words.

VBScriptOnline.com - Clear Method,Execute Method,Raise Method,Replace Method,Test Method