haishSee - 1 year ago 72

C# Question

I want to calculate all the number of characters I have used in a textbox.

For example: If I write this equation in textbox:

5x-2(3y+2)*3y(8)

so what code or line should I write for counting all the parenthesis used here?

Answer Source

var strEquation=textbox1.Text; //5x-2(3y+2)*3y(8)

```
int x = strEquation.Count(c => Char.IsNumber(c)); // 6
int y = strEquation.Count(c => Char.IsLetter(c)); // 3
int total=x+y;
```

Let me know if it works?