I have a simple string (i.e. February 27, 2008) that I need to split
into three parts. The month, day, and year. Splitting into a string
array would work, and I could convert day and years to integers
later. I've bene looking around, and everything I see seems more
complicated than it should be! Help! 4 2800
On Mar 3, 8:49*pm, yogi_bear_79 <yogi_bear...@yahoo.comwrote:
I have a simple string (i.e. February 27, 2008) that I need to split
into three parts. The month, day, and year. *Splitting into a string
array would work, and I could convert day and years to integers
later. *I've bene looking around, and everything I see seems more
complicated than it should be! Help!
If you know the format is exactly as you show above, then it is a
simple matter of finding the spaces.
vector<stringsplitDate( const string& str ) {
vector<stringresult;
string::size_type i = str.find( ' ' );
result.push_back( str.substr( 0, i ) );
string::size_type last = i;
i = str.find( ' ', i + 1 );
result.push_back( str.substr( last, i - last ) );
result.push_back( str.substr( i ) );
return result;
}
If you turn the above into your teacher though, he should grade you
very poorly. You really should have some error checking and probably
some sort of verification code.
But the above should at least get you started.
On Mar 3, 9:08*pm, "Daniel T." <danie...@earthlink.netwrote:
On Mar 3, 8:49*pm, yogi_bear_79 <yogi_bear...@yahoo.comwrote:
I have a simple string (i.e. February 27, 2008) that I need to split
into three parts. The month, day, and year. *Splitting into a string
array would work, and I could convert day and years to integers
later. *I've bene looking around, and everything I see seems more
complicated than it should be! Help!
If you know the format is exactly as you show above, then it is a
simple matter of finding the spaces.
* *vector<stringsplitDate( const string& str ) {
* * * vector<stringresult;
* * * string::size_type i = str.find( ' ' );
* * * result.push_back( str.substr( 0, i ) );
* * * string::size_type last = i;
* * * i = str.find( ' ', i + 1 );
* * * result.push_back( str.substr( last, i - last ) );
* * * result.push_back( str.substr( i ) );
* * * return result;
* *}
If you turn the above into your teacher though, he should grade you
very poorly. You really should have some error checking and probably
some sort of verification code.
But the above should at least get you started.
Thank you so much for the idea. I do believe that it is slightly more
advanced than I shoul dbe at this point. I've settled on the code
below, just as soon as I parrse out the comma!
char longDate[100];
char* nextToken;
cout << " \n Enter a date in the following format(February 27,
2008):";
cin.getline(longDate,100);
char *month = strtok_s(longDate, " ", &nextToken);
char *day = strtok_s(NULL, ",", &nextToken);
char *year = strtok_s(NULL, "\0", &nextToken);
On Mar 3, 9:53*pm, yogi_bear_79 <yogi_bear...@yahoo.comwrote:
On Mar 3, 9:08*pm, "Daniel T." <danie...@earthlink.netwrote:
On Mar 3, 8:49*pm, yogi_bear_79 <yogi_bear...@yahoo.comwrote:
I have a simple string (i.e. February 27, 2008) that I need to split
into three parts. The month, day, and year. *Splitting into a string
array would work, and I could convert day and years to integers
later. *I've bene looking around, and everything I see seems more
complicated than it should be! Help!
If you know the format is exactly as you show above, then it is a
simple matter of finding the spaces.
* *vector<stringsplitDate( const string& str ) {
* * * vector<stringresult;
* * * string::size_type i = str.find( ' ' );
* * * result.push_back( str.substr( 0, i ) );
* * * string::size_type last = i;
* * * i = str.find( ' ', i + 1 );
* * * result.push_back( str.substr( last, i - last ) );
* * * result.push_back( str.substr( i ) );
* * * return result;
* *}
If you turn the above into your teacher though, he should grade you
very poorly. You really should have some error checking and probably
some sort of verification code.
But the above should at least get you started.
Thank you so much for the idea. I do believe that it is slightly more
advanced than I shoul dbe at this point. I've settled on the code
below, just as soon as I parrse out the comma!
* * * * char longDate[100];
* * * * char* nextToken;
* * * * cout << " \n Enter a date in the following format(February27,
2008):";
* * * * cin.getline(longDate,100);
* * * * char *month = strtok_s(longDate, " ", &nextToken);
* * * * char *day = strtok_s(NULL, ",", &nextToken);
* * * * char *year = strtok_s(NULL, "\0", &nextToken);- Hide quoted text -
}
The code you show above is considered much more advanced than what I
showed...
On Mon, 3 Mar 2008 17:49:40 -0800 (PST) in comp.lang.c++,
yogi_bear_79 <yo**********@yahoo.comwrote,
>I have a simple string (i.e. February 27, 2008) that I need to split into three parts. The month, day, and year.
My version: http://groups.google.com/gr*********....earthlink.net This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stuart Gilbert |
last post by:
I'm trying to split a string on every 2 numbers. I presumed the
following would be fine, but I get nothing.
var re = /{8}/;
var regex = new RegExp(re);
if(date.match(regex)) {
var...
|
by: Prasad S |
last post by:
Hello
I wish to replace all the characters in a string except those which
are inside '<' & '>' characters. And there could be multiple
occurences of < & > within the string.
e.g. string =...
|
by: Jeremy Weiss |
last post by:
I'm trying to build a database that will handle the monthly billing needs of
a small company. I'm charting everything out and here's what I see:
table for customers
sub table to track payments...
|
by: tym |
last post by:
HELP!!!
I'm going round the twist with this...
I have a VB6 application which is using DAO to access a database
(Please - no lectures on ADO, I know what I'm doing with DAO!!)
Ok, problem...
|
by: James Radke |
last post by:
Hello,
I have a multithreaded windows NT service application (vb.net 2003) that I
am working on (my first one), which reads a message queue and creates
multiple threads to perform the processing...
|
by: gunimpi |
last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431
********************************************************
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
wanted...
|
by: r035198x |
last post by:
Breaking up a string
Instead of using the old StringTokenizer class, a simple trick is to use the String.split method.
String string = "This is a string";
String tokens = string.split("...
|
by: Sumit |
last post by:
Hi ,
I am trying to splitt a Line whihc is below of format ,
AzAccept PLYSSTM01 "162.44.245.32 CN=dddd
cojack (890),OU=1,OU=Customers,OU=ISM-Users,OU=kkk
Secure,DC=customer,DC=rxcorp,DC=com"...
|
by: jrod11 |
last post by:
hi,
I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |