I have 2 different regex matches and currently using 2 foreach loop to get the match values. However, for now, if one foreach works, then the other doesn't.
Try 1
foreach (string dir in multiTrimmed1)
{
foreach (string dir2 in multiTrimmed2)
{
var forVal2= dir.Replace("$", "").Replace(" ", "");
var forVal3 = dir2.Replace(",", "");
var parsedParams= new ParsedMethod()
{
Value1= forVal1,
Value2 = Convert.ToDecimal(forVal2),
Value3 = Convert.ToDecimal(forVal3),
Value4 = forVal4
};
MergeAllValues(parsedParams);
}
}
So the problem here is that multiTrimmed1 and multiTrimmed2 have string[4] each.
Let's say A, B, C, and D. In my try 1, I want forVal2 and forVal3 to go through the loop correctly.
What I mean by that, when forVal2 is A, forVal3 is also A - send it to MergeAllValues, next, B and B - send it to MergeAllValues, next, C and C - send it to MergeAllValues, and next D and D - send it to MergeAllValues.
Currently only one loop works. If forVal3 value changes to A, B, C, and D -- then forVal2 just stops at A.
Try 2
bool loopAgain = true;
while (loopAgain)
{
loopAgain = false;
foreach (string dir in multiTrimmed1)
{
foreach (string dir2 in multiTrimmed2)
{
var forVal2= dir.Replace("$", "").Replace(" ", "");
var forVal3 = dir2.Replace(",", "");
var parsedParams= new ParsedMethod()
{
Value1= forVal1,
Value2 = Convert.ToDecimal(forVal2),
Value3 = Convert.ToDecimal(forVal3),
Value4 = forVal4
};
MergeAllValues(parsedParams);
loopAgain = true;
break;
}
}
In this case, forVal2 gets the values just fine, but forVal3 stays at A
Try 3
bool loopAgain = true;
while (loopAgain)
{
loopAgain = false;
foreach (string dir in multiTrimmed1)
{
var forVal2= dir.Replace("$", "").Replace(" ", "");
foreach (string dir2 in multiTrimmed2)
{
var forVal3 = dir2.Replace(",", "");
var parsedParams= new ParsedMethod()
{
Value1= forVal1,
Value2 = Convert.ToDecimal(forVal2),
Value3 = Convert.ToDecimal(forVal3),
Value4 = forVal4
};
MergeAllValues(parsedParams);
loopAgain = true;
break;
}
}
Still only work loop works. How can I make both work?