Re: removing brackets from input
"cront" <cront@rocketship.com> wrote in message
news:pan.2007.10.21.04.13.24.723215@rocketship.com...
On Sun, 21 Oct 2007 03:31:26 +0000, robin wrote:
Oh, I got another question: what if there are enclosed bracket-set?
For example: what is the desired output for "a(b(c)d)"?
My above-mentioned solution would result in "a" as output. Is this
what you want?
yes, "a" should be the output but i did not get your these outputs:
Input: comp.lang.(c++)
Output: comp.lang.c++
it should output: comp.lang.
Input: comp.lang.(c++
Output: comp.lang.(c++
this is good.
Input: Bjarn)e St)roustr(up)
Output: Bjarn)e St)roustrup
It should output: Bjarn)e Str)roustr
Input: This ((is) the) way (it (goes)))
Output: This is the way it goes)
It should output: This way
Oh, you want to throw away anything inside of the parenthesis? That's a
simple change.
Where i have:
else if ( Input[i] == ')' && Left != std::string::npos )
{
Right = i - 1;
Input = Input.substr( 0, Left ) + Input.substr( Left + 1 );
Input = Input.substr( 0, Right ) + Input.substr( Right +
1 );
Left = std::string::npos;
Right = std::string::npos;
Found = true;
break;
}
which gets rid of only the parenthsis, just change it to (untested code, may
be off by one)
else if ( Input[i] == ')' && Left != std::string::npos )
{
Right = i;
Input = Input.substr( 0, Left ) + Input.substr( Right );
Left = std::string::npos;
Right = std::string::npos;
Found = true;
break;
}