473,405 Members | 2,167 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,405 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 2302
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
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.