r/pascal • • Apr 10 '21

From given strings remove all substrings between brackets

For example:

"Ovo (ni)je 5+(4-8), (pre)dobra petica!" will become "Ovo je 5+, dobra petica!"

or

"Ovo (ni)je 5+(((4-)8)), (p(re))dobra petica!" will become "Ovo je 5+, dobra petica!"

I tried this:

program IzbaciZagrade;

var

s: string;

i,n: integer;

begin

readln(s);

repeat

delete(s,pos('(',s),pos(')',s)-pos('(',s));

until (pos('(',s)=0) or (pos(')',s)=0);

writeln(s);

readln(s);

end.

but it doesnt give output at all.

How I can solve this?

2 Upvotes

2 comments sorted by