473,407 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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,
Jun 28 '08 #1
4 1283

"puzzlecracker" <ir*********@gmail.coma écrit dans le message de news:
84**********************************...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<stringparsed;
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
Jun 28 '08 #2
On Jun 28, 1:51 pm, "Eric Pruneau" <eric.prun...@cgocable.cawrote:
"puzzlecracker" <ironsel2...@gmail.coma é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<stringparsed;
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?
Jun 29 '08 #3
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
Jun 30 '08 #4
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.

Jul 20 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
3
by: uestebanez | last post by:
Hi everybody! I have a little problem working with libxml SAX API. The problem is that I don't know how to stop parsing when I have processed the data I need. I don't want to parse all file, I...
5
by: gamehack | last post by:
Hi all, I was thinking about parsing equations but I can't think of any generic approach. Basically I have a struct called math_term which is something like: struct math_term { char sign; int...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
3
by: Anup Daware | last post by:
Hi Group, I am facing a strange problem here: I am trying to read xml response from a servlet using XmlTextWriter. I am able to read the read half of the xml and suddenly an exception:...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
1
by: Philip Semanchuk | last post by:
On Oct 12, 2008, at 5:25 AM, S.Selvam Siva wrote: Selvam, You can try to find them yourself using string parsing, but that's difficult. The closer you want to get to "perfect" at finding URLs...
2
by: Felipe De Bene | last post by:
I'm having problems parsing an HTML file with the following syntax : <TABLE cellspacing=0 cellpadding=0 ALIGN=CENTER BORDER=1 width='100%'> <TH BGCOLOR='#c0c0c0' Width='3%'>User ID</TH> <TH...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.