Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: string spli...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 5 Topic 9559 of 9775
Post > Topic >>

Re: string splitting

by "Devdatt Lad" <dlad@[EMAIL PROTECTED] > Apr 30, 2008 at 10:41 AM

> i need to split the above string such that i need to get all these
> parameters.... the field widths are not fixed..i have some times four/
> three digits
> src****t ..so i cant do it with substr function...i need this in c++

Boost provides a handy utility called tokenizer that you can use to do
this.

Check out the following code. Suppose that your input is contained in a
std::string named "user_input".

// create a list to store the resulting separated words from user_input
std::list<std::string> input_args;

// use the tokenizer and specify a single space (" ") as the
char_separator
boost::tokenizer<boost::char_separator<char> > tok(user_input,
boost::char_separator<char>(" "));

// insert the results of the tokenizer into your std::list
std::copy(tok.begin(), tok.end(), std::back_inserter(input_args));

With this you don't have to worry about how many characters you have in
any
of the parts as long as you are sure that you want to separate based on
the
occurrence of white space.

Hope this helps,
Devdatt


-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 5 Posts in Topic:
string splitting
xyz <lavanyareddy.p@[E  2008-04-29 10:43:22 
Re: string splitting
"Hakusa@[EMAIL PROTE  2008-04-29 17:38:05 
Re: string splitting
Alexey Stepanyan <alex  2008-04-29 17:38:54 
Re: string splitting
Alexey Stepanyan <alex  2008-04-29 17:40:29 
Re: string splitting
"Devdatt Lad" &  2008-04-30 10:41:00 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Jul 8 23:22:53 CDT 2008.