473,387 Members | 1,512 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,387 software developers and data experts.

String Parsing in C++

2
Hello everybody, I'm looking for a way for parsing strings.

I' ve something like this:

TOTAL C00 L240 WH00 WPI00 WEI00 WPL00 TDM15359
TEMP49.76 PDIR65535 PREF65535 I28RD65535

TOTAL C08 L230 WH00 WPI00 WEI00 WPL00 TDM15369
TEMP52.21 PDIR65535 PREF65535 I28RD65535

and I need to 'extrapolate' the numeric values in the strings into variables.

For example, I want the bold values in C00 L240 WH00 WPI00 WEI00 WPL00 TDM15359 saved in 3 variables.

How can I manage this problem?
Thx
fafy


I'm thinking to some function/class that make me able to set a pattern 'C..L..TDM...', similarly to the 'textread' function in Matlab
Jun 25 '07 #1
4 2109
niskin
109 100+
Are you aware that in notepad and in a console program you cannot enter anything in bold? What file format do you intend to use to store the text?
Jun 25 '07 #2
fafy
2
Are you aware that in notepad and in a console program you cannot enter anything in bold?
Of course, it was JUST an example to make you know that I want to 'catch' the bold values, that is, to identify them in a better way inside the string!

What file format do you intend to use to store the text?
There isn't any file, data come from serial port (COM1) and I have only to show the numeric values in several fields in a Window dialog box.

To understand, with this string
TOTAL C00 L240 WH00 WPI00 WEI00 WPL00 TDM15369 TEMP49.76 PDIR65535 PREF65535 I28RD65535

my C, L, TDM, TEMP variables should count 00, 240, 15369 and 49.76 respectively
Jun 25 '07 #3
RedSon
5,000 Expert 4TB
Of course, it was JUST an example to make you know that I want to 'catch' the bold values, that is, to identify them in a better way inside the string!


There isn't any file, data come from serial port (COM1) and I have only to show the numeric values in several fields in a Window dialog box.

To understand, with this string
TOTAL C00 L240 WH00 WPI00 WEI00 WPL00 TDM15369 TEMP49.76 PDIR65535 PREF65535 I28RD65535

my C, L, TDM, TEMP variables should count 00, 240, 15369 and 49.76 respectively
So if I understand you, you are getting
Expand|Select|Wrap|Line Numbers
  1. TOTAL C00 L240 WH00 WPI00 WEI00 WPL00 TDM15369 TEMP49.76 PDIR65535 PREF65535 I28RD65535
as your exact output. So then all you need is to read a character from the stream one at a time, and check if its a number or not. Once you have identified if the character is a number then you can do whatever you need to do to it.
Jun 25 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
Go to the C/C++ Articles forum and read the article on the State design pattern. The example in the article is how to do a string parser. I'd rather not paste the article here.

It appears that a State machine is your answer.
Jun 25 '07 #5

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

Similar topics

26
by: Kai Jaensch | last post by:
Hello, i am an newbie and i have to to solve this problem as fast as i can. But at this time i donīt have a lot of success. Can anybody help me (and understand my english :-))? I have a...
18
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
50
by: z. f. | last post by:
HI, i have string in format dd/mm/yyyyy hh:mm:ss and giving this as an input to DateTime.Parse gives a string was not recognized as a valid date time format string error. how do i make the parse...
9
by: Python.LeoJay | last post by:
Dear all, i need to parse billions of numbers from a file into float numbers for further calculation. i'm not satisfied with the speed of atof() function on my machine(i'm using visual c++ 6)....
4
by: Michael Meckelein | last post by:
Hello, Wondering, if C# (framework 2.0) does not support parsing DateTime timezones in three letter acronyms. I would like to parse date strings like "2005 Nov 01 11:58:47.490 CST -6:00" but...
3
by: dimasteg | last post by:
Hi all C. Nead some help with string "on the fly" parsing, how it can be realized ? Any ideas? I got some of my own, but it's interesting to get other points of view . Regards.
9
balabaster
by: balabaster | last post by:
I'm looking for some ideas regarding string parsing and brackets. Say I have the following string: 56*(73+23/(28+(7/14)-(3/2)) What would be the best way to parse the string for each opening...
6
by: James Arnold | last post by:
Hello, I am new to C and I am trying to write a few small applications to get some hands-on practise! I am trying to write a random string generator, based on a masked input. For example, given...
6
by: (2b|!2b)==? | last post by:
I am expecting a string of this format: "id1:param1,param2;id2:param1,param2,param3;id" The tokens are seperated by semicolon ";" However each token is really a struct of the following...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.