Count the total pairs of two characters in a string
Basically I need to count the total number of agrupations inside a string,
this is to display some information like an advise of the total number of
opened submarked expressions in a RegularExpression application.
Then I need to count the total number of closed "()", not the total of "("
and the total of ")" separated.
For example in this string:
Hello (world)
The expected result would be: 1 closed
Here:
Hello (world) ((how are (you)?
The expected result would be: 2 closed and 2 opened
And here:
Hello ) ( World?
The expected result would be: 2 opened
Just pleae can something give me ideas of which can be the improved way to
calculate them?
I got the total amount of "(" and ")" characters, now I don't know what to
do.
No comments:
Post a Comment