Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Extracting numbers from a string

Posted on 2002-07-17
5
Medium Priority
?
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 140 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.
Suggested Courses

604 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