Solved

Extracting numbers from a string

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cell Value from TStringGrid::StringGrid1DrawColumnCell function in C++ builder XE8 3 82
C++ to C# code conversion issue 4 104
Header of docx file 17 102
Precision Problem in C++ 7 31
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

785 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