1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Help, extracting substrings from a string

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

  1. doubty

    doubty New Member

    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

    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