SPLITING A STRING LIKE 10/JULY/1988 AND BIND INTO 3 COMBOBOX SUCH AS DAY ,MONTH,YEAR.
-
HELLO, MY STRING IS DD/MON/YYYY.I WANT TO SPLIT THIS STRING INTO INDIVIDUAL PART LIKE DD,MMM,AND YYYY.AND FINALY BIND THESE INDIVIDUAL VALUE INTO 3 COMBOBOXEX LIKE DAY,MONTH AND YEAR.I HAVE DONE THE CODE BUT ITS WORKING FOR SOME VALUE AND NOT WORKING FOR OTHER. MY CODE: string s = rows[6].ToString();//DOB LIKE 15/JULY/1988 int i = s.IndexOf("/"); t = s.Substring(0, i); t1 = s.Substring(0); t2 = s.Substring(i + 1, i + 2); int i1 = s.IndexOf("/"); t3 = s.Substring(i1 + 5); comboBox2.Text = t.ToString();15 comboBox3.Text = t2.ToString();JULY comboBox4.Text = t3.ToString();1988
-
HELLO, MY STRING IS DD/MON/YYYY.I WANT TO SPLIT THIS STRING INTO INDIVIDUAL PART LIKE DD,MMM,AND YYYY.AND FINALY BIND THESE INDIVIDUAL VALUE INTO 3 COMBOBOXEX LIKE DAY,MONTH AND YEAR.I HAVE DONE THE CODE BUT ITS WORKING FOR SOME VALUE AND NOT WORKING FOR OTHER. MY CODE: string s = rows[6].ToString();//DOB LIKE 15/JULY/1988 int i = s.IndexOf("/"); t = s.Substring(0, i); t1 = s.Substring(0); t2 = s.Substring(i + 1, i + 2); int i1 = s.IndexOf("/"); t3 = s.Substring(i1 + 5); comboBox2.Text = t.ToString();15 comboBox3.Text = t2.ToString();JULY comboBox4.Text = t3.ToString();1988
Have a look at DateTime::Parse and DateTime::ParseExact this should solve your problem. [edit] I don't know why but thanks to this member who rated 1 for this. I think its really the better solution to parse a date time at your own or splitting the string. :thumbsdown: [/edit]
Greetings Covean
modified on Friday, November 13, 2009 7:48 AM
-
Have a look at DateTime::Parse and DateTime::ParseExact this should solve your problem. [edit] I don't know why but thanks to this member who rated 1 for this. I think its really the better solution to parse a date time at your own or splitting the string. :thumbsdown: [/edit]
Greetings Covean
modified on Friday, November 13, 2009 7:48 AM
a little edit
DateTime.Parse
andDateTime.ParseExact
:)TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
----------------------------------------------- 128 bit encrypted signature, crack if you can
-
HELLO, MY STRING IS DD/MON/YYYY.I WANT TO SPLIT THIS STRING INTO INDIVIDUAL PART LIKE DD,MMM,AND YYYY.AND FINALY BIND THESE INDIVIDUAL VALUE INTO 3 COMBOBOXEX LIKE DAY,MONTH AND YEAR.I HAVE DONE THE CODE BUT ITS WORKING FOR SOME VALUE AND NOT WORKING FOR OTHER. MY CODE: string s = rows[6].ToString();//DOB LIKE 15/JULY/1988 int i = s.IndexOf("/"); t = s.Substring(0, i); t1 = s.Substring(0); t2 = s.Substring(i + 1, i + 2); int i1 = s.IndexOf("/"); t3 = s.Substring(i1 + 5); comboBox2.Text = t.ToString();15 comboBox3.Text = t2.ToString();JULY comboBox4.Text = t3.ToString();1988
The date should be stored in the database as a datetime. If so, don't make it a string and then parse it back to a datetime again:
System.DateTime dob = (System.DateTime) rows[6] ;
comboBox2.Text = dob.ToString ( "dd" ) ;
comboBox3.Text = dob.ToString ( "MMMM" ) ;
comboBox4.Text = dob.ToString ( "yyyy" ) ;modified on Thursday, November 12, 2009 10:58 AM
-
a little edit
DateTime.Parse
andDateTime.ParseExact
:)TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
----------------------------------------------- 128 bit encrypted signature, crack if you can
-
HELLO, MY STRING IS DD/MON/YYYY.I WANT TO SPLIT THIS STRING INTO INDIVIDUAL PART LIKE DD,MMM,AND YYYY.AND FINALY BIND THESE INDIVIDUAL VALUE INTO 3 COMBOBOXEX LIKE DAY,MONTH AND YEAR.I HAVE DONE THE CODE BUT ITS WORKING FOR SOME VALUE AND NOT WORKING FOR OTHER. MY CODE: string s = rows[6].ToString();//DOB LIKE 15/JULY/1988 int i = s.IndexOf("/"); t = s.Substring(0, i); t1 = s.Substring(0); t2 = s.Substring(i + 1, i + 2); int i1 = s.IndexOf("/"); t3 = s.Substring(i1 + 5); comboBox2.Text = t.ToString();15 comboBox3.Text = t2.ToString();JULY comboBox4.Text = t3.ToString();1988
Why can't you just use Split? It's difficult to know why it's not working unless we can see which values work and which don't.
-
HELLO, MY STRING IS DD/MON/YYYY.I WANT TO SPLIT THIS STRING INTO INDIVIDUAL PART LIKE DD,MMM,AND YYYY.AND FINALY BIND THESE INDIVIDUAL VALUE INTO 3 COMBOBOXEX LIKE DAY,MONTH AND YEAR.I HAVE DONE THE CODE BUT ITS WORKING FOR SOME VALUE AND NOT WORKING FOR OTHER. MY CODE: string s = rows[6].ToString();//DOB LIKE 15/JULY/1988 int i = s.IndexOf("/"); t = s.Substring(0, i); t1 = s.Substring(0); t2 = s.Substring(i + 1, i + 2); int i1 = s.IndexOf("/"); t3 = s.Substring(i1 + 5); comboBox2.Text = t.ToString();15 comboBox3.Text = t2.ToString();JULY comboBox4.Text = t3.ToString();1988
sudhir behera wrote:
string s = rows[6].ToString();//DOB LIKE 15/JULY/1988
Assuming the contents of
rows[6]
is aDateTime
structure then you can start with that value and extract the day, month and year strings directly by its methods. Take a look at the MSDN documentation here[^] for all the options. -
HELLO, MY STRING IS DD/MON/YYYY.I WANT TO SPLIT THIS STRING INTO INDIVIDUAL PART LIKE DD,MMM,AND YYYY.AND FINALY BIND THESE INDIVIDUAL VALUE INTO 3 COMBOBOXEX LIKE DAY,MONTH AND YEAR.I HAVE DONE THE CODE BUT ITS WORKING FOR SOME VALUE AND NOT WORKING FOR OTHER. MY CODE: string s = rows[6].ToString();//DOB LIKE 15/JULY/1988 int i = s.IndexOf("/"); t = s.Substring(0, i); t1 = s.Substring(0); t2 = s.Substring(i + 1, i + 2); int i1 = s.IndexOf("/"); t3 = s.Substring(i1 + 5); comboBox2.Text = t.ToString();15 comboBox3.Text = t2.ToString();JULY comboBox4.Text = t3.ToString();1988
-
Use Split to split the date by /,- or whichever seperator u use. Then asign the values of each item in array to ur combobox. simplest way and have always worked for me.
FEMDEV wrote:
simplest way
Maybe not the simplest though.
FEMDEV wrote:
always worked for me
Sure, it works, but there is very likely a better way.