Solved

Extracting numbers from a string

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

863 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

22 Experts available now in Live!

Get 1:1 Help Now