473,408 Members | 2,813 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,408 software developers and data experts.

Parsing A String In C++

Hi,

Would anybody tell me an efficient method to parse a string inside a variable which is line separated ...

Like this

value1: line1 /n
value2: line2 /n
value3: line3 /n

i want to parse line y line first and then each of the values by id. Here i am talking about strings coming in at very high rate maybe be 1000s a second.

so it would be nice for you experts to gimme a effcient method for parsing a string inside a string variable(this is not a file).
Jun 12 '07 #1
5 3081
ahammad
79
If you're reading in from a file and the lines are separated by \n, you don't need to "parse". All you have to do is have:

while(!(input.eof())

And in that loop, you would have another loop and put the strings in an array. But this is simply reading in strings like you normally do:

input >> string;

I think that would work, but you should wait for a second opinion.
Jun 12 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
You might try a State machine. Check out the State Design Pattern in the book "Design Patterns" by Erich Fromm, et al. Addison-Wesley 1994.

There is also an article on this pattern in the C/C++ Articles forum.
Jun 12 '07 #3
thanks ahamad for your replys. But i am not looking for parsing a string. What i have is a string variable. I must directly extract that string and do parsing operations on it. As i told you earlier, i am talking about 1000's of such strings per second. so putting into a file and reading it will not be feasible. If you have a better solution please let me know or is file operation feasible if the rate of the operation is 1000/ sec most of the times ?
Jun 13 '07 #4
ahammad
79
How would each line look like and what kind of parsing operations do you have in mind?

For example, someone may want to "parse" a string containing mathematical terms (numbers, equations etc) with their respective values:

pi = 3.1415926
squareArea = length^2
rectArea = length*width
...

So if someone wants to read in each line, and then split them into two parts (the term and its equation), you can do that by using tokenize or other methods. Is this the kind of thing you want to do?
Jun 13 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
thanks ahamad for your replys. But i am not looking for parsing a string. What i have is a string variable. I must directly extract that string and do parsing operations on it. As i told you earlier, i am talking about 1000's of such strings per second. so putting into a file and reading it will not be feasible. If you have a better solution please let me know or is file operation feasible if the rate of the operation is 1000/ sec most of the times ?
Did you read the article on the State design pattern in the C/C++ Articles forum yet??

Part of the example is doing parsing operations on a string.
Jun 14 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
6
by: BerkshireGuy | last post by:
Does anyone know of a good function that will parse out parts of an SQL statement that is passed to it in seperate variables? It should be able to parse statements that contain ORDERBY, WHERE,...
9
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an...
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:...
3
by: aspineux | last post by:
My goal is to write a parser for these imaginary string from the SMTP protocol, regarding RFC 821 and 1869. I'm a little flexible with the BNF from these RFC :-) Any comment ? tests= def...
2
by: RG | last post by:
I am having trouble parsing the data I need from a Serial Port Buffer. I am sending info to a microcontroller that is being echoed back that I need to remove before I start the actual important...
6
by: gw7rib | last post by:
I have a program that needs to do a small amount of relatively simple parsing. The routines I've written work fine, but the code using them is a bit long-winded. I therefore had the idea of...
1
by: hd95 | last post by:
In a perfect world my xml feed source would produce perfect xml ..that is not the case I am parsing an XML feed that sometimes has ampersands and dashes in the content that messes up my parsing. ...
1
by: eyeore | last post by:
Hello everyone my String reverse code works but my professor wants me to use pop top push or Stack code and parsing code could you please teach me how to make this code work with pop top push or...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.