Hi all,
I have following string
0x0002,A5651QPR87GBZ094RTF52,D,A,000001,ABC ,10000.00 , EOT
i need to split the above using ',' as the delimiter & put those in to the following string variables.
1.Command
2.Key
3.Msgtype
4.number
5.name
6.amount
pls reply me as sap.
Regards
Kaushalya
0
Newbie Poster
Recommended Answers
Jump to PostYou can use string.find and string.substr for that
Here's a link with an example
Jump to Postint main() { string str = "0x0002,A5651QPR87GBZ094RTF52,D,A,000001,ABC ,10000.00 , EOT"; string word; stringstream stream(str); while( getline(stream, word, ',') ) cout << word << "\n"; }
Jump to PostNothing magical going on here, but in an uncharacteristic move, I actually added comments. Yes, I'm bored:
#include <string> #include <vector> //! Maintains a collection of substrings that are //! delimited by a string of one or more characters class Splitter { //! Contains the split tokens …
All 9 Replies
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Narue
5,707
Bad Cop
Team Colleague
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
ivailosp
11
Junior Poster
Narue
5,707
Bad Cop
Team Colleague
Kaushalya
0
Newbie Poster
daviddoria
334
Posting Virtuoso
Featured Poster
iamthwee
commented:
No
-2
zwatsu13
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.