Question

I want to find and replace a sort of repetitive strings in my project. I want to use the VS2012 find and replace to make my task easy.

The original string is

Format(Element[Be], Element[Be])

 and I want to replace it following

Element[Be].ToString(Element[Be].Value)

How that can be done using FindAndReplaace feature of VS2012 using REGEX

Was it helpful?

Solution

Try the following regex:

Format\(([^,]*),\s*([^\)]*)\)

and the following replacement string:

$1.ToString($2.Value);

in C#:

var input = "Format(Element[Be], Element[Be])";
var result = Regex.Replace(input, @"Format\(([^,]*),\s*([^\)]*)\)", "$1.ToString($2.Value)");

Regex101 Demo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top