Solved

Extracting numbers from a string

Posted on 2002-07-17
5
173 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now