Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. SPLITING A STRING LIKE 10/JULY/1988 AND BIND INTO 3 COMBOBOX SUCH AS DAY ,MONTH,YEAR.

SPLITING A STRING LIKE 10/JULY/1988 AND BIND INTO 3 COMBOBOX SUCH AS DAY ,MONTH,YEAR.

Scheduled Pinned Locked Moved C#
9 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sudhir behera
    wrote on last edited by
    #1

    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

    C P D L F 5 Replies Last reply
    0
    • S sudhir behera

      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

      C Offline
      C Offline
      Covean
      wrote on last edited by
      #2

      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

      X 1 Reply Last reply
      0
      • C Covean

        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

        X Offline
        X Offline
        Xmen Real
        wrote on last edited by
        #3

        a little edit DateTime.Parse and DateTime.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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

        ----------------------------------------------- 128 bit encrypted signature, crack if you can

        C 1 Reply Last reply
        0
        • S sudhir behera

          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

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • X Xmen Real

            a little edit DateTime.Parse and DateTime.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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

            ----------------------------------------------- 128 bit encrypted signature, crack if you can

            C Offline
            C Offline
            Covean
            wrote on last edited by
            #5

            Yes are right but I think he know what he should do now. ^^

            Greetings Covean

            1 Reply Last reply
            0
            • S sudhir behera

              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

              D Offline
              D Offline
              David Skelly
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • S sudhir behera

                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

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                sudhir behera wrote:

                string s = rows[6].ToString();//DOB LIKE 15/JULY/1988

                Assuming the contents of rows[6] is a DateTime 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.

                1 Reply Last reply
                0
                • S sudhir behera

                  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

                  F Offline
                  F Offline
                  FEMDEV
                  wrote on last edited by
                  #8

                  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.

                  P 1 Reply Last reply
                  0
                  • F FEMDEV

                    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.

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups