I have this string:
string coordinates = @"=ZS123, ZS1234 + 36 + Z(56)S45 + 0";
This string must be converted to another string, depending on the values. The regex finds the values I need to make calculations. Regex matches following values: ZS123, ZS1234, Z(56)S45
Regex regexPattern1 = new Regex(@"(Z.*?S(?:\([^)]+\))?(?:\d+)?)");
string coordinates = @"=ZS123, ZS1234 + 36 + Z(56)S45 + 0";
MatchCollection matchCollection = regexPattern1.Matches(coordinates);
//Piece by piece the coordinates are replaced by other strings, after a calculation has been done with the matched string
foreach (Match match in matchCollection)
{
if (match.Value.StartsWith("ZS("))
{
//calculations
string cellIndex = XY //output
coordinates = coordinates.Replace(match.Value, cellIndex);
//the Match should be replaced with the calculated value(cellindex)
//but of course this leads to a problem by doing it this way
// my coordinates string would be now
//coordinates = XY, XY4 + 36 + Z(56)S45 + 0";
//it should be:
//coordinates = XY, ZS1234 + 36 + Z(56)S45 + 0";
//how to replace the exact match at the right spot once?
}
else if (match.Value.StartsWith("Z(") && match.Value.Contains("S("))
{
//calculations
string cellIndex = //output
coordinates = coordinates.Replace(match.Value, cellIndex);
}
//////else if()
//////
}
I am a novice in programming, thanks a lot for your help. I hope this is so far understandable