8

For Example if this is my equation string,

IF(AND(x>0,x<100),5,IF(AND(x>101,x<200),6,10))

I want to count the no:of occurrences of "IF(" string in the equation.

Opal
  • 81,889
  • 28
  • 189
  • 210
Maria
  • 91
  • 1
  • 1
  • 3

1 Answers1

20

E.g. this way:

def s = "IF(AND(x>0,x<100),5,IF(AND(x>101,x<200),6,10))"
assert 2 == s.count("IF(")

In more advanced example you would probably need to use regex.

Opal
  • 81,889
  • 28
  • 189
  • 210