The input line looks something like this:
LineA: 50
LineB: 120
LineA: 12
LineB: 53
I would like to replace the LineB values ββwith the result of MultiplyCalculatorMethod(LineAValue) , where LineAValue is the value of the line above LineB and MultiplyCalculatorMethod is my other, complex C # method.
In semi-code, I would like to do something like this:
int MultiplyCalculatorMethod(int value) { return 2 * Math.Max(3,value); } string ReplaceValues(string Input) { Matches mat = Regex.Match(LineA:input_value\r\nLineB:output_value) foreach (Match m in mat) { m.output_value = MultiplyCalculatorMethod(m.input_value) } return m.OutputText; } Example: string Text = "LineA:5\r\nLineB:2\r\nLineA:2\r\nLineB:7"; string Result = ReplaceValues(Text);
I wrote a Regex.Match to match LineA: value\r\nLineB: value and get these values ββin groups. But when I use Regex.Replace , I can only provide a βstaticβ result that combines groups from a match, but I cannot use C # methods there.
So my questions are how is Regex.Replace where Result is the result of the C # method, where input is the value of LineA.
c # regex
Tomasz Smykowski
source share