I am trying to replace the values in a string at run time based on the contents within a set of braces.
// this.LinkUrl = "/accounts/{accountId}"
this.LinkUrl = Regex.Replace(account.Company.LinkUrl, @"\{(.*?)\}", "$1");
// this.LinkUrl = "/accounts/accountId"
So far it works as expected and removes the braces. But how can I pass the $1 value into a function, like so
this.LinkUrl = Regex.Replace(account.Company.LinkUrl, @"\{(.*?)\}", this.GetValueForFieldNamed("$1"));
So that “accountid” is replaced with the value the function returns? e.g. “/accounts/56”
You can pass a delegate to the
Regex.Replacemethod that takes aMatchand returns a string, e.g. define the function for replacement:and then call it like this: