Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace value in a vector

Tags:

c++

stl

I want to add the closing parenthesis where the string starts with [[

I tried using find_if, replace_if but it turns out that something isn't right

std::vector<std::string> vector(3);

contains:

    0: text
    1: [[text
    2: text

What I want:

    0: text
    1: [[text]]
    2: text

Could you help with algorithm explanation?

like image 587
Duglas Avatar asked Dec 01 '25 08:12

Duglas


1 Answers

Maybe something like this:

for (std::string & s : vector)
{
    if (s.size() > 1 && s[0] == '[' && s[1] == '[')
        s += "]]";
}

If you want to check for already existing brackets, add some more checks.

like image 150
Kerrek SB Avatar answered Dec 04 '25 00:12

Kerrek SB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!