![]() |
C++ parsing problem
I have the following string pattern string Name, followed by n number
of strings, followed by 2 integers. Such as char * needToParse=" Name, str_1, str_2,...,str_n, integer1, integer2"; parse it so that the following 4 variables contain these values: char *name=Name; char * entry= str1+" "+str2+" "+str_n; int i1=interger1; int i2=interger2, |
Re: C++ parsing problem
"puzzlecracker" <ironsel2000@gmail.com> a écrit dans le message de news: 84ebdaed-fea3-4b86-a6cd-745f14e529c7...oglegroups.com... > I have the following string pattern string Name, followed by n number > of strings, followed by 2 integers. Such as > > char * needToParse=" Name, str_1, str_2,...,str_n, integer1, > integer2"; > > parse it so that the following 4 variables contain these values: > char *name=Name; > char * entry= str1+" "+str2+" "+str_n; > > int i1=interger1; > int i2=interger2, here a simple way to do that int main() { string parse = "Parse me,str1,str2,str3,4,6"; int beg_pos = 0; int end_pos = parse.find(','); vector<string> parsed; while(end_pos > 0) { parsed.push_back(parse.substr(beg_pos, end_pos-beg_pos)); beg_pos = end_pos+1; end_pos = parse.find(',', beg_pos); } return 0; } the string is parsed and results are stored in a vector. Ok I didn't convert the integers but I'm sure you can find a way to do this! ----------------------- Eric Pruneau |
Re: C++ parsing problem
On Jun 28, 1:51 pm, "Eric Pruneau" <eric.prun...@cgocable.ca> wrote:
> "puzzlecracker" <ironsel2...@gmail.com> a écrit dans le message de news: > 84ebdaed-fea3-4b86-a6cd-745f14e52...@m3g2000hsc.googlegroups.com... > > > I have the following string pattern string Name, followed by n number > > of strings, followed by 2 integers. Such as > > > char * needToParse=" Name, str_1, str_2,...,str_n, integer1, > > integer2"; > > > parse it so that the following 4 variables contain these values: > > char *name=Name; > > char * entry= str1+" "+str2+" "+str_n; > > > int i1=interger1; > > int i2=interger2, > > here a simple way to do that > > int main() > { > string parse = "Parse me,str1,str2,str3,4,6"; > > int beg_pos = 0; > int end_pos = parse.find(','); > vector<string> parsed; > while(end_pos > 0) > { > parsed.push_back(parse.substr(beg_pos, end_pos-beg_pos)); > beg_pos = end_pos+1; > end_pos = parse.find(',', beg_pos); > } > return 0; > > } > > the string is parsed and results are stored in a vector. Ok I didn't convert > the integers but I'm sure you can find a way to do this! > > ----------------------- > > Eric Pruneau I am thinking along the lines of sscanf without skipping spaces? |
Re: C++ parsing problem
> I am thinking along the lines of sscanf without skipping spaces? And how will you know how many string there is between the name and the frist integer? ---------------------- Eric Pruneau |
Re: C++ parsing problem
> And how will you know how many string there is between the name and the > frist integer? You wouldn't know, it's a undetermined number of strings between the name and the last two integers. |
| All times are GMT. The time now is 01:10 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.