-5

I get string input like: 1+2*5+sin100-2 and In order to calculate it I need to make array that will look like:

1,+,2,*,5,+,sin,100,-,2

Is there easy solution to do this problem? Currently I am doing it with loop on all the chars in the string but I want to know if c# offer easiest solution to this problem.

Ghasem
  • 14,455
  • 21
  • 138
  • 171
user3100708
  • 148
  • 3
  • 19
  • 5
    Show your *Currently i am doing it with loop* code – Ghasem Feb 09 '16 at 08:46
  • See the last two lines of my answer [here](http://stackoverflow.com/a/35219507/3764814) ;-) – Lucas Trzesniewski Feb 09 '16 at 08:47
  • We cannot guess if there is any better solution then your current one as long as you do not provide the current one. However in any cases I guess this question should go to review-stack instead. – MakePeaceGreatAgain Feb 09 '16 at 08:49
  • 1
    If you have already a working solution it's off-topic on SO anyway. – Tim Schmelter Feb 09 '16 at 08:50
  • 1
    I'm voting to close this question as off-topic because questions about reviewing or improving existing, working code and lacking a specific question statement are off-topic for Stack Overflow. You may be able to get help on [Code Review](http://codereview.stackexchange.com/). – Tim Schmelter Feb 09 '16 at 08:51
  • You can get most of the way with simple regex on split: `\b.\b` – freedomn-m Feb 09 '16 at 08:52
  • @TimSchmelter is *questions about reviewing or improving existing, working code and lacking a specific question statement* in flagging options? Cause I can't find it! – Ghasem Feb 09 '16 at 09:29
  • 1
    @AlexJolig Close - off topic - fourth option : Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example. – freedomn-m Feb 09 '16 at 11:40

1 Answers1

0

I found easy solution.
You could just write it instead of complain that there is no code in the question.

string expression;//my calculator expression
string[] operators;//array that contains both unary and binary operators.
for(int i=0;i<operators.length;i++)
{
   expression = expression.replace(operators[i]," "+operators[i]+ " ");
}
string[] Values= expression.split(" ");
user3100708
  • 148
  • 3
  • 19