Solved

Extracting numbers from a string

Posted on 2002-07-17
5
177 Views
Last Modified: 2010-04-01
I'm trying to extract some numbers from a char buffer formatted something like:

"\r\nSome Text A.B.C\r\nSome other Text D.E.F\r\n"

where a.b.c is the first number and d.e.f is the next number.  I need to get them to be formatted simply "abc" and "def".
0
Comment
Question by:hrasheed
  • 3
5 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 7160732
Are the numbers always going to be before the return-nextline charactor pair?

If so, you can do a charactor search for for the '\r' charactor, and the do a reverse search for the '.' period in order to get the number position.

For more information, please post your existing code.
0
 

Author Comment

by:hrasheed
ID: 7160773
yes, this will always be the format of the returned information.  the existing code isn't really related to formatting this data...i havent begun coding a way to parse these numbers because i wasnt exactly sure what method to use.  the information is written to a char somebuffer[BufferSize].  i'm trying cast the numbers in ulong type for comparison to data read from a parameter file.
0
 
LVL 30

Accepted Solution

by:
Axter earned 35 total points
ID: 7160784
You can use strchr() function to find the '\r' charactor, and then use strrchr() function to reverse find the period charactor.
0
 
LVL 30

Expert Comment

by:Axter
ID: 7160794
You've only awarded 35 points for this question.

http://www.experts-exchange.com/cplusprog/Q_20321305.html
I suggest you delete your above duplicate question so that you can at least assign adaquate points for this question.

You can post a requestion in the Community support topic area to have your duplicate question deleted.
0
 
LVL 1

Expert Comment

by:klf
ID: 7161818
hrasheed

Once you extracted the numbers from the string.  use the atol function to convert them to integers.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Lambda for random numbers problem 7 121
GUI: DIalog Stacking and Popping in MS C++ 4 88
How to Correctly derive class from CWinThread in MFC 4 89
Gaming Software 1 30
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question