1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help, extracting substrings from a string

Discussion in 'C' started by doubty, Jun 18, 2009.

  1. doubty

    doubty New Member

    Joined:
    Jun 18, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    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:
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     

Share This Page