Frage

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

War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top