Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8586285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:16:29+00:00 2026-06-11T22:16:29+00:00

Perhaps someone could tell me what is happening here? My intention is to split

  • 0

Perhaps someone could tell me what is happening here?

My intention is to split an input string on braces: ie: either ‘(‘ or ‘)‘.

For an input string of “(well)hello(there)world” I expect 4 tokens to be returned: well; hello; there; world.

As you can see from my exemplar app below I am getting 5 tokens back (The 1st is an empty string).

Is there any way to get this to return me only the non-empty strings?

#include <iostream>
#include <boost/algorithm/string.hpp>
#include <vector>
int main()
{
    std::string in = "(well)hello(there)world";

    std::vector<std::string> tokens;
    boost::split(tokens, in, boost::is_any_of("()"));

    for (auto s : tokens)
        std::cout << "\"" << s << "\"" << std::endl;

    return 0;
}

Output:

$ a.out
""        <-- where is this token coming from?
"well"
"hello"
"there"
"world"

I have tried using boost::algorithm::token_compress_on but I get the same result.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:16:31+00:00Added an answer on June 11, 2026 at 10:16 pm

    Yes, the first result returned is the empty set {} immediately preceding the first open parenthesis. The behavior is as expected.

    If you don’t want to use that result, simply test for an empty returned variable and discard it.

    To test that this is the expected behavior, put a parenthesis at the end of the line and you will have another empty result at the end. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this newbie here is smacking his head with webservices over Rails. Perhaps someone could
An odd error here, perhaps someone can help track down source as it's attempting
I ´m getting the first steps in R and perhaps someone could help me.
Hi wondering if perhaps someone could shed some light on the below error. The
Perhaps someone could provide some insight into a problem I have. I have a
Only got rough idea of what I want, perhaps someone could pad it out
I'm hoping someone can either tell me what I'm doing wrong correct my flawed
I'm still a bit confused on models and saving data, perhaps someone could help
Perhaps someone can help me out with this one: I'm using a basic search
I have a pretty simple question which perhaps someone familiar with Server/Client design &

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.