Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Help, extracting substrings from a string (http://www.go4expert.com/forums/help-extracting-substrings-string-t18077/)

doubty 18Jun2009 10:33

Help, extracting substrings from a string
 
Hi I have a problem on which Iam working on which requires me to extract substrings from a string as below:

String A(B(A(C(t=0,p>0.1)))) + D(E(t=1,p>0.1))

Substrings needed are: {A(B(A(C(t=0,p>0.1))))+D(E(t=1,p>0.1)),
A(B(A(C(t=0,p>0.1)))),
B(A(C(t=0,p>0.1))),
A(C(t=0,p>0.1)),
C(t=0,p>0.1),
(t=0,p>0.1),
D(E(t=1,p>0.1)),
E(t=1,p>0.1),
(t=1,p>0.1)}

So in effect i have to be able to get all substrings within the brackets.

How can I do it in C

Please help:confused:

xpi0t0s 18Jun2009 13:07

Re: Help, extracting substrings from a string
 
Easy: two nested loops and a counter. Outside loop loops over the string looking for an open bracket. Inside loop loops over the string from the outer loop's index looking for the matching bracket.


All times are GMT +5.5. The time now is 12:59.