简体   繁体   中英

Port code to vb.net

I found some code online. It is in C# and I am trying to port it to vb.net. I need some help with calling the evaluator function from within the Log subroutine. In C#, evaluator does not appear to expect any parameters when it gets called in Log. However, VB keeps asking for the Match parameter. What is the magic and how should I get it to work in VB.NET? Thanks.

private string evaluator(Match match)
{
    Pri pri = new Pri(match.Groups[1].Value);
    return pri.ToString()+" ";
}

private void Log(EndPoint endPoint, string strReceived)
{
...
string strMessage = string.Format("{0} : {1}", 
    endPoint, m_regex.Replace(strReceived, evaluator));
...
}

The C# version is using the (string, MatchEvaluator) overload of Regex.Replace() , and using the implicit conversion of the method name to the MatchEvaluator delegate type. See the MSDN documentation on that overload.

On the MSDN page, this is how they call it:

Dim result As String = rx.Replace(text, AddressOf RegExSample.CapText)

So make sure to use the AddressOf keyword.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM