C#替换为回调函数就像在AS3 [英] C# Replace with Callback Function like in AS3
问题描述
在AS3中,你有一个函数的字符串与此签名:
In AS3 you have a function on a string with this signature:
function replace(pattern:*, repl:Object):String
在REPL:对象也可以指定一个函数。如果指定一个函数,该函数返回的字符串插入替换匹配的内容。
The repl:Object can also specify a function. If you specify a function, the string returned by the function is inserted in place of the matching content.
此外,是有可能得到的,我要替换的东西原始字符串?
Also, is it possible to get the the original string in which I want to replace things?
(在AS3中,你可以通过
(In AS3 you can get the original string by
var input:String = arguments[2]; //in the callback function
)
我没有看到匹配
类包含原始字符串的属性...
I don't see a property in the Match
class containing the original string...
推荐答案
为了做到这一点在C#中,使用 System.Text.RegularEx pressions.Regex.Replace()
这需要一个回调。
In order to do this in C#, use System.Text.RegularExpressions.Regex.Replace()
which takes a callback.
这篇关于C#替换为回调函数就像在AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!