Bonjour,
Il y a quelques temps j'avais trouvé une classe sur le net me permettant de calculer le résultat d'une opération mathématique contenue dans une chaîne de caractère, comme par exemple :

String operation = "2*5+9/3";
Voici la classe en question (a cas où ca intéresserait quelqu'un):

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
 
/// <summary>
	/// This class is used to convert a string expression to a numeric one, 
	/// to evaluate this numeric expression and to reconvert the result back
	/// to string
	/// </summary>
	public class FormulaGenerator
	{
		#region constructors
		/// <summary>
		/// implicit constructor
		/// </summary>
		public FormulaGenerator()
		{
 
		}//FormulaGenerator
		#endregion constructors
 
 
		#region public members
		public static string EvaluationResult(string astrexpr)
		{
			try
			{
				if (astrexpr == "") astrexpr = "0";
				EvalExpr(astrexpr);
				return m_strservice;
			}
			catch(Exception aobjExc)
			{
                return "ERROR";
			}
		}//EvaluationResult
		#endregion public members
 
 
		#region private members
		//this alghoritm work  for expression with any level of parenthesis 
		private static void EvalExpr(string astrexpr)
		{
			if(ExistParenthesis(astrexpr))
			{
				int iposleftparenthesis = PosMaxLevel(astrexpr);
				string strtemp = astrexpr.Substring(iposleftparenthesis + 1);
				int iposrightparenthesis = FindFirstChar(strtemp, ')');
				string strbetweenparenthesis = strtemp.Substring(0, iposrightparenthesis);
 
				EvalAritm(strbetweenparenthesis.Trim());
 
				string strbefore = astrexpr.Substring(0,iposleftparenthesis);
				string strafter = astrexpr.Substring(iposleftparenthesis + iposrightparenthesis + 2);
				EvalExpr(strbefore + m_strservice + strafter);
			}
			else EvalAritm(astrexpr.Trim());
 
		}//EvalExpr
 
 
		private static bool ExistParenthesis(string astrexpr)
		{
			m_iCharContor = 0;
			int inbleft = 0;
			NbOfChar(astrexpr,'(');
			inbleft = m_iCharContor;
 
			m_iCharContor = 0;
			int inbright = 0;
			NbOfChar(astrexpr, ')');
			inbright = m_iCharContor;
 
			if(inbleft != inbright) throw new Exception("Sintax Error!");
			if (inbleft == 0) return false;
			return true;
		}//ExistParenthesis
 
 
		private static int PosMaxLevel(string astrexpr)
		{
			int ipos = -1;
			int ilevel = 0;
			int maxlevel = LevelOfParenthesis(astrexpr);
 
			foreach(char ch in astrexpr.ToCharArray())
			{
				ipos+=1;
				if(ch == '(')
				{
					ilevel += 1;
					if(ilevel == maxlevel)
					{
						return ipos;
					}
				}
				else if(ch == ')')
				{
					ilevel -= 1;
				}
			}
 
			return 0;
		}//PosMaxLevel
 
 
 
		private static int LevelOfParenthesis(string astrexpr)
		{
			int ilevel = 0;
			int ipos = -1;
			int maxlevel = 0;
			foreach(char ch in astrexpr.ToCharArray())
			{
				ipos += 1;
				if(ch == '(')
				{
					ilevel = ilevel + 1;
				}
				else if(ch == ')')
				{
					ilevel -= 1;
				}
				if(maxlevel < ilevel)
				{
					maxlevel = ilevel;
				}
			}
			return maxlevel;
		}//LevelOfParenthesis
 
 
 
		private static int FindLastChar(string astrexpr, char acfinder)
		{
			return astrexpr.LastIndexOf(acfinder);
		}//FindLastChar
 
 
		private static int FindFirstChar(string astrexpr, char acfinder)
		{
			return astrexpr.IndexOf(acfinder);
		}//FindFirstChar
 
 
		private static int FindSecondChar(string astrexpr, char acfinder)
		{
			int ifirst = astrexpr.IndexOf(acfinder);
			int isecond = astrexpr.Substring(ifirst + 1).IndexOf(acfinder);
			return ifirst + isecond + 1;
		}//FindSecondChar
 
 
		private static void NbOfChar(string astrexpr, char acfinder)
		{
			int i = astrexpr.IndexOf(acfinder);
			if(i >= 0)
			{
				m_iCharContor+=1;
				NbOfChar(astrexpr.Substring(i+1),acfinder);
			}
		}//NbOfChar
 
 
		private static void EvalAritm(string astrexpr)
		{
			ProcessPercent(astrexpr);
			string strwithoutpercent = m_strservice;
 
			ProcessDivision(strwithoutpercent);
			string strwithoutdivision = m_strservice;
 
			ProcessMultiply(strwithoutdivision);
			string strwithoutmultiply = m_strservice;
 
			ProcessMinus(strwithoutmultiply);
			string strwithoutminus = m_strservice;
 
			ProcessPlus(strwithoutminus);
			string strwithoutplus = m_strservice;
		}//EvalAritm
 
 
		private static void ProcessPercent(string astrexpr)
		{
			m_iCharContor = 0;
			NbOfChar(astrexpr,'%');
			int inbpercent = m_iCharContor;
 
			string strnewastrexpr = astrexpr.Trim();
			m_iCharContor = 0;
			NbOfChar(strnewastrexpr, '%');
			if(m_iCharContor == 0)
			{
				m_strservice = strnewastrexpr;
			}
			if(inbpercent > 0)
			{
				string astrexprwithoutbreak = astrexpr.Trim();
				int ipospercent = FindFirstChar(astrexprwithoutbreak,'%');
				string astrwithoutpercent;
				if (ipospercent >= 1)
				{
					astrwithoutpercent = astrexprwithoutbreak.Substring(0,ipospercent);
				}
				else
				{
					throw new Exception("Sintax error!");
				}
 
				int ilastdivision = FindLastChar(astrwithoutpercent,'/');
				int ilastmultiply = FindLastChar(astrwithoutpercent,'*');
				int ilastminus = FindLastChar(astrwithoutpercent,'-');
				int ilastplus = FindLastChar(astrwithoutpercent,'+');
 
 
				ArrayList arlsigns = new ArrayList();
				arlsigns.Add(ilastdivision);
				arlsigns.Add(ilastmultiply);
				arlsigns.Add(ilastminus);
				arlsigns.Add(ilastplus);
				int imaxsignpos = NbMax(arlsigns);
				if(imaxsignpos < 0) imaxsignpos = 0;
 
				string strpercent;
				string strbeforepercent;
				if(imaxsignpos >= 1)
				{
					strpercent = astrwithoutpercent.Substring(imaxsignpos + 1).Trim();
					strbeforepercent = astrwithoutpercent.Substring(0,imaxsignpos+1).Trim();
				}
				else
				{
					strpercent = astrwithoutpercent.Trim();
					strbeforepercent = "";
				}
 
				string strafterpercent="";
				if(ipospercent < astrexprwithoutbreak.Length - 1) 
				{
					strafterpercent = astrexprwithoutbreak.Substring(ipospercent+1).Trim();
				}
 
				decimal dpercentvalue = ConvertToValue(strpercent);
				strnewastrexpr = strbeforepercent + Convert.ToString(dpercentvalue) + strafterpercent;
				ProcessPercent(strnewastrexpr);
			}
		}//ProcessPercent
 
 
		private static void ProcessDivision(string astrexpr)
		{
			m_iCharContor = 0;
			NbOfChar(astrexpr,'/');
			int inbdivision = m_iCharContor;
 
			string strnewastrexpr = astrexpr.Trim();
			m_iCharContor = 0;
			NbOfChar(strnewastrexpr, '/');
			if(m_iCharContor == 0)
			{
				m_strservice = strnewastrexpr;
			}
 
			if(inbdivision > 0)
			{
				string astrexprwithoutbreak = astrexpr.Trim();
				int iposdivision = FindFirstChar(astrexprwithoutbreak,'/');
				string astrbeforedivision;
				if (iposdivision >= 1)
				{
					astrbeforedivision = astrexprwithoutbreak.Substring(0,iposdivision).Trim();
				}
				else
				{
					throw new Exception("Division error!");
				}
 
				string astrafterdivision;
				if(iposdivision < astrexprwithoutbreak.Length - 1)
				{
					astrafterdivision = astrexprwithoutbreak.Substring(iposdivision + 1).Trim();
				}
				else
				{
					throw new Exception("Division error!");
				}
 
				int ilastdivisionbefore = FindLastChar(astrbeforedivision,'/');
				int ilastmultiplybefore = FindLastChar(astrbeforedivision,'*');
				int ilastminusbefore = FindLastChar(astrbeforedivision,'-');
				int ilastplusbefore = FindLastChar(astrbeforedivision,'+');
 
				int ilastdivisionafter = FindFirstChar(astrafterdivision,'/');
				int ilastmultiplyafter = FindFirstChar(astrafterdivision,'*');
				int ilastminusafter = FindFirstChar(astrafterdivision,'-');
				int ilastplusafter = FindFirstChar(astrafterdivision,'+');
 
				ArrayList arlsignsbefore = new ArrayList();
				arlsignsbefore.Add(ilastdivisionbefore);
				arlsignsbefore.Add(ilastmultiplybefore);
				arlsignsbefore.Add(ilastminusbefore);
				arlsignsbefore.Add(ilastplusbefore);
				int imaxsignpos = NbMax(arlsignsbefore);
				if (imaxsignpos <= 0) imaxsignpos = -1;
 
				ArrayList arlsignsafter = new ArrayList();
				arlsignsafter.Add(ilastdivisionafter);
				arlsignsafter.Add(ilastmultiplyafter);
				arlsignsafter.Add(ilastminusafter);
				arlsignsafter.Add(ilastplusafter);
				int iminsignpos = NbMin(arlsignsafter);
				if (iminsignpos <= 0) iminsignpos = 0; 
 
				string strbeforedivisionafter = astrbeforedivision.Substring(imaxsignpos + 1).Trim();
				string strbeforedivisionbefore = astrbeforedivision.Substring(0,imaxsignpos + 1).Trim();
 
				string strafterdivisionbefore = astrafterdivision.Substring(0,iminsignpos).Trim();
				string strafterdivisionafter = astrafterdivision.Substring(iminsignpos).Trim();
 
				bool issignbefore = false;
				if(strbeforedivisionbefore.Length > 0)
				{
					if(strbeforedivisionbefore.Substring(0,1).Trim() == "-")
					{
						issignbefore = true;
					}
				}
 
				bool issignafter = false;
				if(strafterdivisionbefore.Length > 0)
				{
					if(strafterdivisionbefore.Substring(0,1).Trim() == "-")
					{
						issignafter = true;
					}
				}
 
				decimal dbeforedivision;
				if(strbeforedivisionafter.Length > 0)
				{
					dbeforedivision = Convert.ToDecimal(SetDecimalSeparator(strbeforedivisionafter));
				}
				else if(strbeforedivisionbefore.Length > 0)
				{
					dbeforedivision = Convert.ToDecimal(SetDecimalSeparator(strbeforedivisionbefore));
				}
				else dbeforedivision = 0;
 
				decimal dafterdivision;
				if(strafterdivisionbefore.Length > 0)
				{
					dafterdivision = Convert.ToDecimal(SetDecimalSeparator(strafterdivisionbefore));
				}
				else if(strafterdivisionafter.Length > 0)
				{
					dafterdivision = Convert.ToDecimal(SetDecimalSeparator(strafterdivisionafter));
				}
				else dafterdivision = 1;
 
				decimal ddivision=0;
				if(dafterdivision != 0)
				{
					if(issignbefore || issignafter)
					{
						ddivision = (-1) * dbeforedivision / dafterdivision;
					}
					else ddivision = dbeforedivision / dafterdivision;
				}
 
				strnewastrexpr = strbeforedivisionbefore + Convert.ToString(ddivision) + strafterdivisionafter;
				if(strafterdivisionbefore == "") strnewastrexpr = strbeforedivisionbefore + Convert.ToString(ddivision);
				ProcessDivision(strnewastrexpr);
			}
		}//ProcessDivision
 
 
 
		private static void ProcessMultiply(string astrexpr)
		{
			m_iCharContor = 0;
			NbOfChar(astrexpr,'*');
			int inbmultiply = m_iCharContor;
 
			string strnewastrexpr = astrexpr.Trim();
			m_iCharContor = 0;
			NbOfChar(strnewastrexpr, '*');
			if(m_iCharContor == 0)
			{
				m_strservice = strnewastrexpr;
			}
 
			if(inbmultiply > 0)
			{
				string astrexprwithoutbreak = astrexpr.Trim();
				int iposmultiply = FindFirstChar(astrexprwithoutbreak,'*');
				string astrbeforemultiply;
				if (iposmultiply >= 1)
				{
					astrbeforemultiply = astrexprwithoutbreak.Substring(0,iposmultiply).Trim();
				}
				else
				{
					throw new Exception("Error!");
				}
 
				string astraftermultiply;
				if(iposmultiply < astrexprwithoutbreak.Length - 1)
				{
					astraftermultiply = astrexprwithoutbreak.Substring(iposmultiply + 1).Trim();
				}
				else
				{
					throw new Exception("Error!");
				}
 
				int ilastdivisionbefore = FindLastChar(astrbeforemultiply,'/');
				int ilastmultiplybefore = FindLastChar(astrbeforemultiply,'*');
				int ilastminusbefore = FindLastChar(astrbeforemultiply,'-');
				int ilastplusbefore = FindLastChar(astrbeforemultiply,'+');
 
				int ilastdivisionafter = FindFirstChar(astraftermultiply,'/');
				int ilastmultiplyafter = FindFirstChar(astraftermultiply,'*');
				int ilastminusafter = FindFirstChar(astraftermultiply,'-');
				int ilastplusafter = FindFirstChar(astraftermultiply,'+');
 
				ArrayList arlsignsbefore = new ArrayList();
				arlsignsbefore.Add(ilastdivisionbefore);
				arlsignsbefore.Add(ilastmultiplybefore);
				arlsignsbefore.Add(ilastminusbefore);
				arlsignsbefore.Add(ilastplusbefore);
				int imaxsignpos = NbMax(arlsignsbefore);
				if (imaxsignpos <= 0) imaxsignpos = -1;
 
				ArrayList arlsignsafter = new ArrayList();
				arlsignsafter.Add(ilastdivisionafter);
				arlsignsafter.Add(ilastmultiplyafter);
				arlsignsafter.Add(ilastminusafter);
				arlsignsafter.Add(ilastplusafter);
				int iminsignpos = NbMin(arlsignsafter);
				if (iminsignpos <= 0) iminsignpos = 0; 
 
				string strbeforemultiplyafter = astrbeforemultiply.Substring(imaxsignpos + 1).Trim();
				string strbeforemultiplybefore = astrbeforemultiply.Substring(0,imaxsignpos + 1).Trim();
 
				string straftermultiplybefore = astraftermultiply.Substring(0,iminsignpos).Trim();
				string straftermultiplyafter = astraftermultiply.Substring(iminsignpos).Trim();
 
				bool issignbefore = false;
				if(strbeforemultiplybefore.Length > 0)
				{
					if(strbeforemultiplybefore.Substring(0,1).Trim() == "-")
					{
						//issignbefore = true;
					}
				}
 
				bool issignafter = false;
				if(straftermultiplybefore.Length > 0)
				{
					if(straftermultiplybefore.Substring(0,1).Trim() == "-")
					{
						issignafter = true;
					}
				}
 
				decimal dbeforemultiply;
				if(strbeforemultiplyafter.Length > 0)
				{
					if(IsDigit(strbeforemultiplyafter) == true)
					{
						dbeforemultiply = Convert.ToDecimal(SetDecimalSeparator(strbeforemultiplyafter));
					}
					else
					{
						dbeforemultiply = ConvertToValue(strbeforemultiplyafter);
					}
				}
				else if(strbeforemultiplybefore.Length > 0)
				{
					if(IsDigit(strbeforemultiplybefore) == true)
					{
						dbeforemultiply = Convert.ToDecimal(SetDecimalSeparator(strbeforemultiplybefore));
					}
					else
					{
						dbeforemultiply = ConvertToValue(strbeforemultiplybefore);
					}
				}
				else dbeforemultiply = 0;
 
				decimal daftermultiply;
				if(straftermultiplybefore.Length > 0)
				{
					if(IsDigit(straftermultiplybefore) == true)
					{
						daftermultiply = Convert.ToDecimal(SetDecimalSeparator(straftermultiplybefore));
					}
					else
					{
						daftermultiply = ConvertToValue(straftermultiplybefore);
					}
				}
				else if(straftermultiplyafter.Length > 0)
				{
					if(IsDigit(straftermultiplyafter) == true)
					{
						daftermultiply = Convert.ToDecimal(SetDecimalSeparator(straftermultiplyafter));
					}
					else
					{
						daftermultiply = ConvertToValue(straftermultiplyafter);
					}
				}
				else daftermultiply = 0;
 
				decimal dmultiply=0;
				if(daftermultiply != 0)
				{
					if(issignbefore || issignafter)
					{
						dmultiply = (-1) * dbeforemultiply * daftermultiply;
					}
					else dmultiply = dbeforemultiply * daftermultiply;
				}
 
				strnewastrexpr = strbeforemultiplybefore + Convert.ToString(dmultiply) + straftermultiplyafter;
				if(straftermultiplybefore == "") strnewastrexpr = strbeforemultiplybefore + Convert.ToString(dmultiply);
				ProcessMultiply(strnewastrexpr);
			}
		}//ProcessMultiply
 
 
		private static void ProcessMinus(string astrexpr)
		{
			m_iCharContor = 0;
			NbOfChar(astrexpr,'-');
 
			int iposminustest = FindFirstChar(astrexpr.Trim(),'-');
			//if(iposminustest == 0) iposminustest = this.FindSecondChar(astrexpr.Trim(),'-');
 
			string strnewastrexpr = astrexpr.Trim();
			m_iCharContor = 0;
			NbOfChar(strnewastrexpr, '-');
			if(iposminustest == 0)m_iCharContor -= 1;
			int inbminus = m_iCharContor;
			if(m_iCharContor == 0)
			{
				m_strservice = strnewastrexpr;
			}
 
			if(inbminus > 0)
			{
				string astrexprwithoutbreak = astrexpr.Trim();
				//if(iposminustest == 0) astrexprwithoutbreak = astrexprwithoutbreak.Substring(1);
				int iposminus = FindFirstChar(astrexprwithoutbreak,'-');
				if (iposminus == 0)iposminus = FindSecondChar(astrexprwithoutbreak,'-'); 
				string astrbeforeminus;
				if (iposminus >= 1)
				{
					astrbeforeminus = astrexprwithoutbreak.Substring(0,iposminus).Trim();
				}
				else
				{
					astrbeforeminus = astrexprwithoutbreak.Substring(0,iposminus).Trim();
				}
 
				string astrafterminus;
				if(iposminus < astrexprwithoutbreak.Length - 1)
				{
					astrafterminus = astrexprwithoutbreak.Substring(iposminus + 1).Trim();
					//if(iposminustest == 0)astrafterminus = astrafterminus.Substring(1).Trim();
				}
				else
				{
					throw new Exception("Error!");
				}
 
				int ilastdivisionbefore = FindLastChar(astrbeforeminus,'/');
				int ilastmultiplybefore = FindLastChar(astrbeforeminus,'*');
				int ilastminusbefore = FindLastChar(astrbeforeminus,'-');
				int ilastplusbefore = FindLastChar(astrbeforeminus,'+');
 
				int ilastdivisionafter = FindFirstChar(astrafterminus,'/');
				int ilastmultiplyafter = FindFirstChar(astrafterminus,'*');
				int ilastminusafter = FindFirstChar(astrafterminus,'-');
				int ilastplusafter = FindFirstChar(astrafterminus,'+');
 
				ArrayList arlsignsbefore = new ArrayList();
				arlsignsbefore.Add(ilastdivisionbefore);
				arlsignsbefore.Add(ilastmultiplybefore);
				arlsignsbefore.Add(ilastminusbefore);
				arlsignsbefore.Add(ilastplusbefore);
				int imaxsignpos = NbMax(arlsignsbefore);
				if (imaxsignpos <= 0) imaxsignpos = -1;
 
				ArrayList arlsignsafter = new ArrayList();
				arlsignsafter.Add(ilastdivisionafter);
				arlsignsafter.Add(ilastmultiplyafter);
				arlsignsafter.Add(ilastminusafter);
				arlsignsafter.Add(ilastplusafter);
				int iminsignpos = NbMin(arlsignsafter);
				if (iminsignpos <= 0) iminsignpos = 0; 
 
				string strbeforeminusafter = astrbeforeminus.Substring(imaxsignpos + 1).Trim();
				string strbeforeminusbefore = astrbeforeminus.Substring(0,imaxsignpos + 1).Trim();
 
				string strafterminusbefore = astrafterminus.Substring(0,iminsignpos).Trim();
				string strafterminusafter = astrafterminus.Substring(iminsignpos).Trim();
 
				decimal dbeforeminus = 0;
				if(strbeforeminusafter.Length > 0)
				{
					if(IsDigit(strbeforeminusafter) == true)
					{
						dbeforeminus = Convert.ToDecimal(SetDecimalSeparator(strbeforeminusafter));
					}
					else
					{
						dbeforeminus = ConvertToValue(strbeforeminusafter);
					}
				}
				else if(strbeforeminusbefore.Length > 0)
				{
					if(IsDigit(strbeforeminusbefore) == true)
					{
						dbeforeminus = Convert.ToDecimal(SetDecimalSeparator(strbeforeminusbefore));
					}
					else
					{
						dbeforeminus = ConvertToValue(strbeforeminusbefore);
					}
				}
 
				decimal dafterminus = 0;
				if(strafterminusbefore.Length > 0)
				{
					if(IsDigit(strafterminusbefore))
					{
						dafterminus = Convert.ToDecimal(SetDecimalSeparator(strafterminusbefore));
					}
					else
					{
						dafterminus = ConvertToValue(strafterminusbefore);
					}
				}
				else if(strafterminusafter.Length > 0)
				{
					if(IsDigit(strafterminusafter))
					{
						dafterminus = Convert.ToDecimal(SetDecimalSeparator(strafterminusafter));
					}
					else
					{
						dafterminus = ConvertToValue(strafterminusafter);
					}
				}
 
				decimal dminus=0;
				dminus = dbeforeminus - dafterminus;
 
				strnewastrexpr = strbeforeminusbefore + Convert.ToString(dminus) + strafterminusafter;
				if(strafterminusbefore == "") strnewastrexpr = strbeforeminusbefore + Convert.ToString(dminus);
 
				ProcessMinus(strnewastrexpr);
			}
		}//ProcessMinus
 
 
		private static void ProcessPlus(string astrexpr)
		{
			m_iCharContor = 0;
			NbOfChar(astrexpr,'+');
			int inbplus = m_iCharContor;
 
			string strnewastrexpr = astrexpr.Trim();
			m_iCharContor = 0;
			NbOfChar(strnewastrexpr, '+');
			if(m_iCharContor == 0)
			{
				m_strservice = strnewastrexpr;
			}
 
			if(inbplus > 0)
			{
				string astrexprwithoutbreak = astrexpr.Trim();
				int iposplus = FindFirstChar(astrexprwithoutbreak,'+');
				string astrbeforeplus;
				if (iposplus >= 1)
				{
					astrbeforeplus = astrexprwithoutbreak.Substring(0,iposplus).Trim();
				}
				else
				{
					throw new Exception("Error!");
				}
 
				string astrafterplus;
				if(iposplus < astrexprwithoutbreak.Length - 1)
				{
					astrafterplus = astrexprwithoutbreak.Substring(iposplus + 1).Trim();
				}
				else
				{
					throw new Exception("Error!");
				}
 
				int ilastdivisionbefore = FindLastChar(astrbeforeplus,'/');
				int ilastmultiplybefore = FindLastChar(astrbeforeplus,'*');
				int ilastminusbefore = FindLastChar(astrbeforeplus,'-');
				int ilastplusbefore = FindLastChar(astrbeforeplus,'+');
 
				int ilastdivisionafter = FindFirstChar(astrafterplus,'/');
				int ilastmultiplyafter = FindFirstChar(astrafterplus,'*');
				int ilastminusafter = FindFirstChar(astrafterplus,'-');
				int ilastplusafter = FindFirstChar(astrafterplus,'+');
 
				ArrayList arlsignsbefore = new ArrayList();
				arlsignsbefore.Add(ilastdivisionbefore);
				arlsignsbefore.Add(ilastmultiplybefore);
				arlsignsbefore.Add(ilastminusbefore);
				arlsignsbefore.Add(ilastplusbefore);
				int imaxsignpos = NbMax(arlsignsbefore);
				if (imaxsignpos <= 0) imaxsignpos = -1;
 
				ArrayList arlsignsafter = new ArrayList();
				arlsignsafter.Add(ilastdivisionafter);
				arlsignsafter.Add(ilastmultiplyafter);
				arlsignsafter.Add(ilastminusafter);
				arlsignsafter.Add(ilastplusafter);
				int iminsignpos = NbMin(arlsignsafter);
				if (iminsignpos <= 0) iminsignpos = 0; 
 
				string strbeforeplusafter = astrbeforeplus.Substring(imaxsignpos + 1).Trim();
				string strbeforeplusbefore = astrbeforeplus.Substring(0,imaxsignpos + 1).Trim();
 
				string strafterplusbefore = astrafterplus.Substring(0,iminsignpos).Trim();
				string strafterplusafter = astrafterplus.Substring(iminsignpos).Trim();
 
				decimal dbeforeplus = 0;
				if(strbeforeplusafter.Length > 0)
				{
					if(IsDigit(strbeforeplusafter) == true)
					{
						dbeforeplus = Convert.ToDecimal(SetDecimalSeparator(strbeforeplusafter));
					}
					else
					{
						dbeforeplus = ConvertToValue(strbeforeplusafter);
					}
				}
				else if(strbeforeplusbefore.Length > 0)
				{
					if(IsDigit(strbeforeplusbefore) == true)
					{
						dbeforeplus = Convert.ToDecimal(SetDecimalSeparator(strbeforeplusbefore));
					}
					else
					{
						dbeforeplus = ConvertToValue(strbeforeplusbefore);
					}
				}
 
 
				decimal dafterplus = 0;
				if(strafterplusbefore.Length > 0)
				{
					if(IsDigit(strafterplusbefore) == true)
					{
						dafterplus = Convert.ToDecimal(SetDecimalSeparator(strafterplusbefore));
					}
					else
					{
						dafterplus = ConvertToValue(strafterplusbefore);
					}
				}
				else if(strafterplusafter.Length > 0)
				{
					if(IsDigit(strafterplusafter) == true)
					{
						dafterplus = Convert.ToDecimal(SetDecimalSeparator(strafterplusafter));
					}
					else
					{
						dafterplus = ConvertToValue(strafterplusafter);
					}
				}
 
 
				decimal dplus=0;
				dplus = dbeforeplus + dafterplus;
 
				strnewastrexpr = strbeforeplusbefore + Convert.ToString(dplus) + strafterplusafter;
				if(strafterplusbefore == "") strnewastrexpr = strbeforeplusbefore + Convert.ToString(dplus);
				ProcessPlus(strnewastrexpr);
			}
			else
			{
				if(IsDigit(astrexpr) == false)
				{
					ConvertToValue(astrexpr);
				}
			}
		}//ProcessPlus
 
 
		private static decimal ConvertToValue(string astrexpr)
		{
 
			bool bmarker = true;
			decimal dexpr = 0;
			for(int i=0;i <= astrexpr.Length - 1;i++)
			{
				string strlocal = astrexpr.Substring(i,1);
				if ((i != 0) || (strlocal != "-"))
				{
					char[] ch = strlocal.ToCharArray();
					if((Char.IsDigit(ch[0]) == false) && (strlocal != ".") && (strlocal != ",") /*&& (strlocal != " ")*/)
					{
						bmarker = false;
					}
				}
			}
 
			if(bmarker == true)
			{
				dexpr = Convert.ToDecimal(astrexpr)/100;
			}
			else
			{
 
				throw new Exception("Not numeric value!");
			}
 
			return dexpr;
		}//ConvertToValue
 
 
		private static int NbMax(ArrayList aobjarl)
		{
			int max = 0;
			foreach(object obj in aobjarl)
			{
				if((int)obj != -1)
				{
					if(max <= (int)obj) max = (int)obj;
				}
			}
			return max;
		}//NbMax
 
 
		private static int NbMin(ArrayList aobjarl)
		{
			int min = NbMax(aobjarl);
			foreach(object obj in aobjarl)
			{
				if((int)obj != -1)
				{
					if(min >= (int)obj) min = (int)obj;
				}
			}
			return min;
		}//NbMin
 
 
		private static bool IsDigit(string astrexpr)
		{
			foreach(char ch in astrexpr.ToCharArray())
			{
				if((ch != '-')&&(ch != ' ')&&(ch != '.')&&(ch != ','))
				{
					if (Char.IsDigit(ch) == false)
					{
						return false;
					}
				}
			}
			return true;
		}//IsDigit
 
 
		private static string SetDecimalSeparator(string astrexpr)
		{
			string strseparator = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
			int ipoint = astrexpr.IndexOf('.');
			int icomma = astrexpr.IndexOf(',');
			string newastrexpr;
 
			if(ipoint >= 0)
			{
				newastrexpr = astrexpr.Replace(".",strseparator);
			}
			else if(icomma >= 0)
			{
				newastrexpr = astrexpr.Replace(",",strseparator);
			}
			else
			{
				newastrexpr = astrexpr;
			}
			return newastrexpr;
		}//SetDecimalSeparator
 
 
		private static int m_iCharContor = 0;
		private static string m_strservice = "";
		private static double m_iNbOfMinus = 0;
		private static string m_strExpression;
 
 
 
		#endregion private members
 
 
 
 
 
	}
Cependant cette classe ne permet de calculer que les opérations élémentaires ( + - * / ) ainsi que le %.


Connaisseriez vous par hasard une librairie / ou une classe du framework que j'aurais loupé, qui permettrait de calculer des opérations moins basiques, comme le log, exp etc ...

J'ai beau fouiller msdn et google, je n'ai pour l'instant rien trouvé ...

Merci d'avance