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

Parsing a string

I need to parse a string which is like
ACS*PR*1*101.55**2*-22**66*166*68~
The data between the asterisks should go to sepate strings (string1, string2
etc)
Can I string instead of c-string?
Any help is appreciated.

Thanks in advance.
Jul 17 '07 #1
6 2293
In article <E5**********************************@microsoft.co m>,
=?Utf-8?B?c2F0aA==?= <sa**@discussions.microsoft.comwrote:
>I need to parse a string which is like
ACS*PR*1*101.55**2*-22**66*166*68~
The data between the asterisks should go to sepate strings (string1, string2
etc)
If you're matching things between single '*'s, then strchr is your
friend for finding the next instance of a character in a
string. Fairly easy to make a loop that calls strchr and strdup if
you're doing c-strings.

Nathan Mates

--
<*Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein
Jul 17 '07 #2

"sath" <sa**@discussions.microsoft.comwrote in message
news:E5**********************************@microsof t.com...
>I need to parse a string which is like
ACS*PR*1*101.55**2*-22**66*166*68~
The data between the asterisks should go to sepate strings (string1,
string2
etc)
Can I string instead of c-string?
Any help is appreciated.

Thanks in advance.
You may want to look into the function strtok().

http://msdn2.microsoft.com/en-us/lib...sb(VS.80).aspx
Jul 17 '07 #3
In article <eo**************@TK2MSFTNGP05.phx.gbl>,
PvdG42 <pv**@toadstool.eduwrote:
>You may want to look into the function strtok().
http://msdn2.microsoft.com/en-us/lib...sb(VS.80).aspx
Why are people pushing that braindamaged bit of code? strtok is
*dangerous*. Library functions that have globals behind your back are
a recipe for disaster. It's only slightly better than gets(). See
things like: http://xp-framework.info/xml/xp.en_US/news/view?31

Sure, MS might have fixed some of the evil with strtok_s. If so,
then recommend it, and only it. But, as the original poster is using
single characters to separate things, then strchr/strrchr will do the
trick, and is *SAFE*.

Nathan Mates
--
<*Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein
Jul 17 '07 #4

"sath" <sa**@discussions.microsoft.comwrote in message
news:E5**********************************@microsof t.com...
>I need to parse a string which is like
ACS*PR*1*101.55**2*-22**66*166*68~
The data between the asterisks should go to sepate strings (string1,
string2
etc)
Can I string instead of c-string?
Any help is appreciated.
Since you're posting in the C++/CLI group, try System::String::Split
>
Thanks in advance.

Jul 17 '07 #5
sath <sa**@discussions.microsoft.comwrote:
I need to parse a string which is like
ACS*PR*1*101.55**2*-22**66*166*68~
The data between the asterisks should go to sepate strings (string1, string2
etc)
Can I string instead of c-string?
Any help is appreciated.
If speed doesn't matter, you can put it into a
stringstream and read with 'std::getline()' using '*'
as the EOL char until you hit EDF. Or look into the
'std::string::find...()' family of functions and use
one of these together with 'std::string::substr()'.
Both ways avoid C-strings.
Thanks in advance.
HTH,

Schobi

--
Sp******@gmx.de is never read
I'm HSchober at gmx dot de
"If there were some arcane way to remove the heads of every
newsgroup troll on the planet, I think it would elevate
humans to a whole new level of intelligence."
Rocky Frisco
Jul 17 '07 #6

"Nathan Mates" <na****@visi.comwrote in message
news:13*************@corp.supernews.com...
In article <eo**************@TK2MSFTNGP05.phx.gbl>,
PvdG42 <pv**@toadstool.eduwrote:
>>You may want to look into the function strtok().
http://msdn2.microsoft.com/en-us/lib...sb(VS.80).aspx

Why are people pushing that braindamaged bit of code? strtok is
*dangerous*. Library functions that have globals behind your back are
a recipe for disaster. It's only slightly better than gets(). See
things like: http://xp-framework.info/xml/xp.en_US/news/view?31

Sure, MS might have fixed some of the evil with strtok_s. If so,
then recommend it, and only it. But, as the original poster is using
single characters to separate things, then strchr/strrchr will do the
trick, and is *SAFE*.

Nathan Mates
--
While I'm sure you have a point, why the reference to this "XP Framework",
which appears to be some sort of class library for PHP? Links from the cited
article all lead to PHP.

Jul 17 '07 #7

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

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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.