Arithme Calc(List <Arithme> lNext) { var tt = lNext.FindAll(vx => vx.Operation != null).OrderBy(vy => vy.Operation.Order).ToList(); if (tt.Count > 0) { try { foreach (var arithme in tt) { int ind = lNext.IndexOf(arithme); double.TryParse(lNext[ind - 1].Svalue, out double val1); double.TryParse(lNext[ind + 1].Svalue, out double val2); if (NewMath.IsFunctionExiste(lNext[ind - 1].Svalue)) { double.TryParse(NewMath.ExecuteFunction(lNext[ind - 1].Svalue), out val1); } if (NewMath.IsFunctionExiste(lNext[ind + 1].Svalue)) { double.TryParse(NewMath.ExecuteFunction(lNext[ind + 1].Svalue), out val2); } var res = Calculate(val1, val2, arithme.Operation.Signe); lNext.RemoveAt(ind - 1); lNext.RemoveAt(ind - 1); lNext.RemoveAt(ind - 1); lNext.Insert(ind - 1, new Arithme(res.ToString(), null)); } } catch (Exception) { Console.WriteLine("Une erreur est survenue lors du calcule de votre chaine, Merci de le verifier"); } } else { try { if (NewMath.IsFunctionExiste(lNext[0].Svalue)) { string result = NewMath.ExecuteFunction(lNext[0].Svalue); lNext.Clear(); lNext.Add(new Arithme(result, null)); } } catch (Exception) { Console.WriteLine("Une erreur est survenue lors du calcule de votre chaine, Merci de le verifier"); } } return(lNext.Single()); }
private string CreateCleanString(string myString, ref int indexStart, ref int indexEnd, ref bool dansLaParenthese) { string cleanString = ""; for (int i = 0; i < myString.Length; i++) { char c = myString[i]; if (c.Equals(')')) { if (i >= 0 && !NewMath.IsFunctionExiste(cleanString)) { indexEnd += 1; dansLaParenthese = false; } } if (dansLaParenthese) { indexEnd += 1; cleanString += c; } else if (indexEnd == 0) { cleanString += c; } if (c.Equals('(')) { if (i >= 0 && !NewMath.IsFunctionExiste(cleanString)) { indexStart = i; indexEnd = 1; dansLaParenthese = true; cleanString = ""; } } } return(cleanString); }