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. Text break into two part

Text break into two part

Scheduled Pinned Locked Moved C#
csharphelptutorialquestionlearning
11 Posts 7 Posters 1 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.
  • M mjawadkhatri

    hi, i am beginner in c#, i need tour help, i want two break textbox text in two part For example textbox1.text = "ABT-001" ABT-001 break into "ABT-00" and "1" textbox2.text = "ABT-00" and textbox3.text="1" Hope you understand by question Thanks

    OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #2

    You are looking for the String.Substring method[^] What it does it returns a new string, cut down from the original. You just have to specify the start position of the new string (in characters from the beginning of the original) and the length of the new string, in characters:

    int len = textBox1.Text.Length;
    textbox2.Text = textBox1.Text.Substring(0, len - 1);
    textbox3.text = textbox1.Text.Substring(len - 1);

    (if you don't specify the length, you get the whole remaining string).

    Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

    1 Reply Last reply
    0
    • M mjawadkhatri

      hi, i am beginner in c#, i need tour help, i want two break textbox text in two part For example textbox1.text = "ABT-001" ABT-001 break into "ABT-00" and "1" textbox2.text = "ABT-00" and textbox3.text="1" Hope you understand by question Thanks

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #3

      Why would anyone vote you down for that? Beginners have to start somewhere, and English isn't everybody's native language. Compensated.

      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      L A 2 Replies Last reply
      0
      • OriginalGriffO OriginalGriff

        Why would anyone vote you down for that? Beginners have to start somewhere, and English isn't everybody's native language. Compensated.

        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

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

        OriginalGriff wrote:

        Why would anyone vote you down for that?

        A trend that seems to be increasingly common. There are obviously a (I hope small) number of people whose only contribution to CodeProject is to down vote those questions they deem unworthy. I guess in a population this size there will always be a percentage of morons.

        I must get a clever new signature for 2011.

        OriginalGriffO 1 Reply Last reply
        0
        • L Lost User

          OriginalGriff wrote:

          Why would anyone vote you down for that?

          A trend that seems to be increasingly common. There are obviously a (I hope small) number of people whose only contribution to CodeProject is to down vote those questions they deem unworthy. I guess in a population this size there will always be a percentage of morons.

          I must get a clever new signature for 2011.

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #5

          Richard MacCutchan wrote:

          morons.

          I can think of another word which fits them better. Starts with "A"... :laugh:

          Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          N 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Richard MacCutchan wrote:

            morons.

            I can think of another word which fits them better. Starts with "A"... :laugh:

            Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #6

            Assets ? :-D


            I know the language. I've read a book. - _Madmatt Two letters away from being an asset

            OriginalGriffO 1 Reply Last reply
            0
            • N Not Active

              Assets ? :-D


              I know the language. I've read a book. - _Madmatt Two letters away from being an asset

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #7

              Close enough! :laugh:

              Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              1 Reply Last reply
              0
              • M mjawadkhatri

                hi, i am beginner in c#, i need tour help, i want two break textbox text in two part For example textbox1.text = "ABT-001" ABT-001 break into "ABT-00" and "1" textbox2.text = "ABT-00" and textbox3.text="1" Hope you understand by question Thanks

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #8

                What pattern do you want to use to break the text apart? Do you want to break it based on the length? Is it based on a particular string pattern, e.g. XXX-NN representing the first part? Before anybody can offer you a definitive answer, you need to explain the problem fully.

                I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                Forgive your enemies - it messes with their heads

                My blog | My articles | MoXAML PowerToys | Onyx

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  Why would anyone vote you down for that? Beginners have to start somewhere, and English isn't everybody's native language. Compensated.

                  Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                  A Offline
                  A Offline
                  Abhinav S
                  wrote on last edited by
                  #9

                  Amazing - you got downvoted! Compensated.

                  The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick

                  OriginalGriffO 1 Reply Last reply
                  0
                  • A Abhinav S

                    Amazing - you got downvoted! Compensated.

                    The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #10

                    Now, I wonder who did that? :laugh: Was it an As...

                    Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    1 Reply Last reply
                    0
                    • M mjawadkhatri

                      hi, i am beginner in c#, i need tour help, i want two break textbox text in two part For example textbox1.text = "ABT-001" ABT-001 break into "ABT-00" and "1" textbox2.text = "ABT-00" and textbox3.text="1" Hope you understand by question Thanks

                      V Offline
                      V Offline
                      Valery Possoz
                      wrote on last edited by
                      #11

                      Hi, Without knowing exactly what criteria you want to use to split the string it is a bit difficult to give a definite answer. Something you could look at and that is really powerful is Regular Expressions (RegEx) Here are a few samples found using google: http://msdn.microsoft.com/en-us/library/8yttk7sy.aspx[^] http://www.codeproject.com/Answers/147947/How-to-split-string-to-two-text-boxes.aspx#answer2[^] Hope it helps. Valery.

                      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