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:Object 也可以指定一个函数.如果指定一个函数,则该函数返回的字符串被插入到匹配内容的位置.
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
)
我在 Match
类中没有看到包含原始字符串的属性...
I don't see a property in the Match
class containing the original string...
推荐答案
为了在 C# 中做到这一点,使用 System.Text.RegularExpressions.Regex.Replace()
,它需要一个回调.
In order to do this in C#, use System.Text.RegularExpressions.Regex.Replace()
which takes a callback.
这篇关于C# 替换为 AS3 中的回调函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!