473,699 Members | 2,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help splitting a simple date string

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!
Mar 4 '08 #1
4 2820
On Mar 3, 8:49*pm, yogi_bear_79 <yogi_bear...@y ahoo.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<stringsp litDate( const string& str ) {
vector<stringre sult;
string::size_ty pe i = str.find( ' ' );
result.push_bac k( str.substr( 0, i ) );
string::size_ty pe last = i;
i = str.find( ' ', i + 1 );
result.push_bac k( str.substr( last, i - last ) );
result.push_bac k( 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.

Mar 4 '08 #2
On Mar 3, 9:08*pm, "Daniel T." <danie...@earth link.netwrote:
On Mar 3, 8:49*pm, yogi_bear_79 <yogi_bear...@y ahoo.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<strings plitDate( const string& str ) {
* * * vector<stringre sult;
* * * string::size_ty pe i = str.find( ' ' );
* * * result.push_bac k( str.substr( 0, i ) );
* * * string::size_ty pe last = i;
* * * i = str.find( ' ', i + 1 );
* * * result.push_bac k( str.substr( last, i - last ) );
* * * result.push_bac k( 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(lon gDate,100);

char *month = strtok_s(longDa te, " ", &nextToken);
char *day = strtok_s(NULL, ",", &nextToken);
char *year = strtok_s(NULL, "\0", &nextToken);
Mar 4 '08 #3
On Mar 3, 9:53*pm, yogi_bear_79 <yogi_bear...@y ahoo.comwrote:
On Mar 3, 9:08*pm, "Daniel T." <danie...@earth link.netwrote:


On Mar 3, 8:49*pm, yogi_bear_79 <yogi_bear...@y ahoo.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<strings plitDate( const string& str ) {
* * * vector<stringre sult;
* * * string::size_ty pe i = str.find( ' ' );
* * * result.push_bac k( str.substr( 0, i ) );
* * * string::size_ty pe last = i;
* * * i = str.find( ' ', i + 1 );
* * * result.push_bac k( str.substr( last, i - last ) );
* * * result.push_bac k( 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(lon gDate,100);

* * * * char *month = strtok_s(longDa te, " ", &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...

Mar 4 '08 #4
On Mon, 3 Mar 2008 17:49:40 -0800 (PST) in comp.lang.c++,
yogi_bear_79 <yo**********@y ahoo.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
Mar 5 '08 #5

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

Similar topics

6
1767
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 dateArray = new Array(4); dateArray = date.split(/{2}/);
4
1894
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 = "this is an example of <how> many words could be hidden <under> these characters" now, from this string all the characters should be searched & replaced
18
12805
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 received. No biggie, right? Well, here's my problem. I don't know how to tell access to modify everyone's account balance each month. And I can't just always assume that their monthly bill is $16 just because their balance is $16. If I do that...
9
5165
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 is this.... importing a large csv file (189000 lines, 7 fileds per line)
6
4991
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 for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a PDF. It works fine so far....
0
5569
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 ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
4
21672
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(" "); for(String s: tokens) { System.out.println(s); }
2
1329
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" "plysmhc03zp GET /mci/performance/ SelectProducts.aspx? p=0&V=C&a=29&menu=adhoc" Here all the string whihc i want to split is
5
4946
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 there are, it crashes. There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)? Here is a link: http://www.jaredmoore.com/tablesorter/docs/salestable.html Here is some jquery js that I think...
0
8685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8613
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9032
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8908
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7745
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4374
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.