473,396 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Retrieving numbers from a string

I'm trying to read numbers from a string with the format
'(1,2,3,4,5)'. Each number needs to go into the array, number[].
If the input string is not formatted as above, an error message will
be outputted. The numbers do not have to be of type int(can be
fractions) I know I need to separate the string into smaller
substrings then convert the substrings to type double to be placed
into the array but I'm stuck at what to do first.

Can anyone help me with this?
Thanks,
Jesse(ga******@aol.com)
Jul 22 '05 #1
2 1428
Hi,
"Jesse" <ga******@ufl.edu> wrote in message
news:9d**************************@posting.google.c om...
I'm trying to read numbers from a string with the format
'(1,2,3,4,5)'. Each number needs to go into the array, number[].
If the input string is not formatted as above, an error message will
be outputted. The numbers do not have to be of type int(can be
fractions) I know I need to separate the string into smaller
substrings then convert the substrings to type double to be placed
into the array but I'm stuck at what to do first.

Can anyone help me with this?

Something like the following should work.

Replace '(' and ',' with space then use stringstream to retrieve doubles:

#include <algorithm>
#include <vector>
#include <string>
#include <sstream>

using namespace std;

replace_if( Number.begin(), Number.end(), bind2nd( equal_to<char>(), '(' ),
' ' );
replace_if( Number.begin(), Number.end(), bind2nd( equal_to<char>(), ')' ),
' ' );
replace_if( Number.begin(), Number.end(), bind2nd( equal_to<char>(), ',' ),
' ' );

stringstream NumberStream( Number );
double Frac;
vector< double > NumberVec;

wihle( NumberStream >> Frac )
{
NumberVec.push_back( Frac );
}
Regards, Ron AF Greve.

Thanks,
Jesse(ga******@aol.com)

Jul 22 '05 #2
Try a "while" loop around sscanf.

Jesse wrote:
I'm trying to read numbers from a string with the format
'(1,2,3,4,5)'. Each number needs to go into the array, number[].
If the input string is not formatted as above, an error message will
be outputted. The numbers do not have to be of type int(can be
fractions) I know I need to separate the string into smaller
substrings then convert the substrings to type double to be placed
into the array but I'm stuck at what to do first.

Can anyone help me with this?
Thanks,
Jesse(ga******@aol.com)


Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Plat | last post by:
I've Googled this for a while, to no avail. Hopefully someone can help me. Maybe I'm using the wrong terminology. Here's the scoop! Let's say I've got a simple *.ASPX page that has a syntax...
13
by: RHPT | last post by:
I am wanting to capture the XML posted by an InfoPath form with .NET, but I cannot figure out how to capture the XML stream sent back by the InfoPath form. With Classic ASP, I could just create an...
5
by: jan axelson | last post by:
My application is using RegisterDeviceNotification() to detect attachment and removal of a USB HID-class device. The form is receiving WM_DEVICECHANGE messages with wParam set to...
8
by: Chris Braun | last post by:
Hi. I need to retrieve the product version of a specific file from within my VB.Net application so that I can determine if the application has the correct version from a third party supplier. ...
2
by: Sakke | last post by:
Hello! We have written a GCryptoSvr.dll COM server in C++. Inside that resides WebClient COM component. WebClient CLSID is {8DC27D48-F94C-434B-A509-C3E1A3E75B9E}. When we are using that...
1
by: jimmyfo | last post by:
Hi, I recently wrote an ASP.Net web application in VS2005 and published (using VS2005 Publish feature) it to a relatively clean machine with ASP.Net 2.0 and MDAC 2.8 installed on it. However, when...
5
by: Sanjay Pais | last post by:
I have a table with over 1.3 million rows. I am retrieving only 20 at a time using the with - over clauses In query analyser, the data is retrieved in under a second. When retrieving using the...
2
by: shivapadma | last post by:
i have inserted the image into database using the following code String driverName = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/"; String dbName =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.