split string c# based on math operator -
split string c# based on math operator -
(calculator program)count in 1 step math basic order
if there string = "5+2*6/9"(which user input) how number 2 , 6? i've been trying split if there no '+' fail :(
here code atm
string[] = kalimat.split('*'); string[] a1 = a[0].split('+'); string[] a2 = a1[a1.count() - 1].split('-'); string[] b1 = a[1].split('+'); string[] b2 = b1[0].split('-'); ang1 = a2[a2.count() - 1]; ang2 = b2[0]; angka1 = convert.todouble(ang1); angka2 = convert.todouble(ang2); hasil = angka1 * angka2;
any thought guys?
if you're input look in form: "[some number]+[first value want return]*[second value want return]" should work you:
var reg = new system.text.regularexpressions.regex(@"\d\+(\d)\*(\d)"); var result = reg.match("5+2*6/9"); var first = result.groups[1]; var sec = result.groups[2];
you can of course of study tweak regular look search pattern suit needs.
c# split
Comments
Post a Comment