Vbs Tutorial: method-replace Method

Source: Internet
Author: User

Replace Method

Replace the text found in the regular expression search.

Object. Replace (String1, string2)

Parameters

Object

Required. Always oneRegexpObject Name.

String1

Required.String1Is the string to be replaced by text.

String2

Required.String2Is to replace the text string.

Description

The actual mode of the replaced text is throughRegexpObjectPatternAttribute.

ReplaceMethod returnString1InRegexp. PatternThe text has been replacedString2. If no matching text is found, the originalString1.

The example below illustratesReplaceMethod usage.

Function replacetest (patrn, replstr) dim RegEx, str1'Create a variable.Str1 = "The quick brown fox jumped over the lazy dog ."Set RegEx = new Regexp'Create a regular expression.RegEx. pattern = patrn'Set the mode.RegEx. ignorecase = true'Set whether to be case sensitive.Replacetest =RegEx. Replace (Str1,Replstr)'.End FunctionMsgbox (replacetest ("Fox", "cat "))'Set'Fox'Replace'Cat'.

In addition,ReplaceMethod to replace subexpressions in the mode. Next, replace all the word pairs in the original string with the calls to functions in the previous example:

 
Msgbox (replacetext ("(\ s +)", "$3 $2 $1 "))'Exchange word pairs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.