hi Developers
How enter Multiple values in a single Textbox and how to Split it and How to Calculate it on both Running time and C#.
i have a Textbox named txtDetails i should enter Many values or More than one value .
i want to Split it by + or - or * and perform the calculation.
if i entered values like this 10+20-10*2/5 the result will be =8.(like a simple calculator)
i can give Decimals too.
else
if i entered values like this 20 the result will be =20. thats all
this is my requirement still i have been trying with google. if anyone of know how to do this please guide me to i am done this task quickly.
thanking you
Paul.S
Prayer throw, Impossible becomes Possible.


Mangesh GRank #294 · 8.6K reputationPosted Dec 8, 2016, 3:00 AM EST
string[] reslts = dataentered.Split(new char[] { '+', '-','*','/' }, StringSplitOptions.RemoveEmptyEntries);
string withoutNumbers = Regex.Replace(dataentered, "[0-9]", "");
char[] Operatorarray = withoutNumbers.ToCharArray();
for (int i = 0; i <= Operatorarray.Length-1; i++)
{
if (reslts.ElementAtOrDefault(i+1) != null)
{
txt3.Text =
DoProcessing(Operatorarray[i].ToString(), Convert.ToDouble(reslts[i]),
Convert.ToDouble(reslts[i + 1])).ToString();
}
}
public double DoProcessing( string logic, double x, double y)
{
switch (logic)
{
case "+": return x + y;
break;
case "-": return x - y;
case "*": return x * y;
case "/": return x / y;
}
return 0;
}
Salman BegRank #284 · 8.8K reputationPosted Dec 8, 2016, 12:38 AM EST
Amit GuptaRank #190 · 12.8K reputationPosted Dec 8, 2016, 12:47 AM EST
Paul RajsRank #2,423 · 582 reputationPosted Dec 8, 2016, 1:04 AM EST
Salman BegRank #284 · 8.8K reputationPosted Dec 8, 2016, 1:11 AM EST
Paul RajsRank #2,423 · 582 reputationPosted Dec 8, 2016, 1:16 AM EST
Salman BegRank #284 · 8.8K reputationPosted Dec 8, 2016, 1:22 AM EST
Paul RajsRank #2,423 · 582 reputationPosted Dec 8, 2016, 1:33 AM EST
Amit GuptaRank #190 · 12.8K reputationPosted Dec 8, 2016, 1:39 AM EST
Paul RajsRank #2,423 · 582 reputationPosted Dec 8, 2016, 1:51 AM EST
Salman BegRank #284 · 8.8K reputationPosted Dec 8, 2016, 2:48 AM EST
Amit GuptaRank #190 · 12.8K reputationPosted Dec 8, 2016, 4:32 AM EST
Paul RajsRank #2,423 · 582 reputationPosted Dec 8, 2016, 8:49 PM EST