split string - better way?
-
Hi, I have to split a string in the format mm/dd/yyyy. This is what I do:
CString date,sMM,sDD,sYY,str; int yy,mm,dd; // date\_poleSet = CString object date in the format mm/dd/yyyy // the month,day and year have to be seperated into int mm,dd,yy int offset = date\_poleSet.Find('/'); date = date\_poleSet; sMM = date\_poleSet.Left(offset); mm = atoi(sMM); // gives the month str = date.Mid(offset+1); offset = str.Find('/'); date = str; sDD = str.Left(offset); dd = atoi(sDD); // gives the day sYY = date.Mid(offset+1); yy = atoi(sYY); // gives the year
Is this good enough? Or can it be done in two or three lines?
Thanks, Tara
You could also use a COleDateTime[^] object: you "load" the date using the ParseDateTime method and then you can retrieve all the information you need using the different member functions. The big advantage is that it checks for the date validity, which is a pain if you have to do it yourself (months don't have the same number of days and you have to take into account leap years too :sigh: ).
Cédric Moonen Software developer
Charting control [v1.3] -
Have you considered
COleDateTime::ParseDateTime()
?"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
Damn, you beat me to it ;P
Cédric Moonen Software developer
Charting control [v1.3] -
Damn, you beat me to it ;P
Cédric Moonen Software developer
Charting control [v1.3]I guess my CPMRU was fully charged.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
You could also use a COleDateTime[^] object: you "load" the date using the ParseDateTime method and then you can retrieve all the information you need using the different member functions. The big advantage is that it checks for the date validity, which is a pain if you have to do it yourself (months don't have the same number of days and you have to take into account leap years too :sigh: ).
Cédric Moonen Software developer
Charting control [v1.3] -
Thank you. I shall look into ParseDateTime. Didn't know about that! Although for now, what you showed me (left,right, mid) is perfect for what I am trying to do.
Thanks, Tara
Tara14 wrote:
what you showed me
It was not me ;) Anyway, it all depends from where your date is coming from: if it entered by a user of your program, then it is better to check its validity.
Cédric Moonen Software developer
Charting control [v1.3] -
I guess my CPMRU was fully charged.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
Keep it in mind that no matter how charged it is, there may be some queries with which the CPMRU will not help you at all. ;P
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
-
Keep it in mind that no matter how charged it is, there may be some queries with which the CPMRU will not help you at all. ;P
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
Indeed. That's a documented bug....won't be fixed for a few releases. Good luck.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I guess my CPMRU was fully charged.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Damn, you beat me to it ;P
Cédric Moonen Software developer
Charting control [v1.3]Cedric Moonen wrote:
you beat me to it
Using Sticks?? :doh: :laugh:
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/codeProject$$>
-
It is a 'private' joke. It means "Code Project Mind Reader Unit". It appeared recently because a lot of questions that were asked were so incomplete that you had to either see the screen of the guy or read his mind :rolleyes:
Cédric Moonen Software developer
Charting control [v1.3]