本文介绍了如何搜索数字并反转它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对不起题主,不过笨东西什么都不接受.我正在努力做到这一点
sorry about the title, but the stupid thing did not accept anything.I am triyng to do this
Dim myString, myResult
myString = "Hello World! 1234 Hello World! 4321 Hello World! 6789"
Set myRegex = New RegExp
myRegex.Global = true
myRegex.IgnoreCase = true
myRegex.Pattern = "([0-9]+)"
myResult = myRegex.Replace(myString, StrReverse("$1"))
我希望所有的数字都反转我希望字符串看起来像这样你好世界!4321 你好世界!1234 你好世界!9876"但我得到的只是1$"
I want all the numbers to reverseI want the string to look like this "Hello World! 4321 Hello World! 1234 Hello World! 9876"but all I get is "1$"
谢谢:-)
推荐答案
您可以使用 替换函数:
Function Reverse(m, pos, src)
Reverse = StrReverse(m)
End Function
Set re = New RegExp
re.Pattern = "\d+"
re.Global = True
s = "Hello World! 1234 Hello World! 4321 Hello World! 6789"
WScript.Echo re.Replace(s, GetRef("Reverse"))
输出:
Hello World! 4321 Hello World! 1234 Hello World! 9876
仅仅调用 re.Replace(s, StrReverse("$1"))
是行不通的,因为在这个语句中,StrReverse
反转了之前的字符串 "$1"re.Replace()
被调用.
Just calling re.Replace(s, StrReverse("$1"))
won't work, because in this statement, StrReverse
reverses the string "$1" before re.Replace()
is called.
这篇关于如何搜索数字并反转它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!