博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何使replace方法不区分大小写(转)
阅读量:2492 次
发布时间:2019-05-11

本文共 819 字,大约阅读时间需要 2 分钟。

被替换的文本的实际模式是通过 RegExp 对象的 Pattern 属性设置的。

Replace 方法返回 string1 的副本,其中的 RegExp.Pattern 文本已经被替换为 string2。如果没有找到匹配的文本,将

返回原来的 string1 的副本。

下面的例子说明了 Replace 方法的用法。

Function ReplaceTest(patrn, replStr)

 Dim regEx, str1        ' 建立变量。
 str1 = "The quick brown fox jumped over the lazy dog."
 Set regEx = New RegExp        ' 建立正则表达式。
 regEx.Pattern = patrn        ' 设置模式。
 regEx.IgnoreCase = True        ' 设置是否区分大小写。
 ReplaceTest = regEx.Replace(str1, replStr)     ' 作替换。
End Function

MsgBox(ReplaceTest("fox", "cat"))      ' 将 'fox' 替换为 'cat'。

;另外,Replace 方法在模式中替换 subexpressions 。 下面对以前示例中函数的调用,替换了原字符串中的所有字
对:

MsgBox(ReplaceText("(S+)(s+)(S+)", "$3$2$1"))     ' 交换词对.

要求的脚本语言在5.0以上

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-124656/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-124656/

你可能感兴趣的文章