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 GPosted Dec 8, 2016, 8:00 AM
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;
}
Paul RajsPosted Dec 9, 2016, 1:49 AM
Amit GuptaPosted Dec 8, 2016, 9:32 AM
Salman BegPosted Dec 8, 2016, 7:48 AM
Paul RajsPosted Dec 8, 2016, 6:51 AM
Amit GuptaPosted Dec 8, 2016, 6:39 AM
Paul RajsPosted Dec 8, 2016, 6:33 AM
Salman BegPosted Dec 8, 2016, 6:22 AM
Paul RajsPosted Dec 8, 2016, 6:16 AM
Salman BegPosted Dec 8, 2016, 6:11 AM
Paul RajsPosted Dec 8, 2016, 6:04 AM
Amit GuptaPosted Dec 8, 2016, 5:47 AM
Salman BegPosted Dec 8, 2016, 5:38 AM