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. Trim() doesn't work!!

Trim() doesn't work!!

Scheduled Pinned Locked Moved C#
csharpc++
7 Posts 5 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.
  • R Offline
    R Offline
    Rickard Andersson20
    wrote on last edited by
    #1

    This code doesn't work for me:

    String str = this.textBox1.Text;
    String newStr = str.Trim();
    MessageBox.Show(newStr);

    The MessageBox that appears contain the string WITH all white spaces!!! Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C# and C++!

    D N A L 4 Replies Last reply
    0
    • R Rickard Andersson20

      This code doesn't work for me:

      String str = this.textBox1.Text;
      String newStr = str.Trim();
      MessageBox.Show(newStr);

      The MessageBox that appears contain the string WITH all white spaces!!! Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C# and C++!

      D Offline
      D Offline
      David Wengier
      wrote on last edited by
      #2

      Trim only removes leading and trailing whitespace. It doesnt remove the spaces between words etc. Is that what you mean? -- David Wengier Sonork ID: 100.14177 - Ch00k

      R 1 Reply Last reply
      0
      • R Rickard Andersson20

        This code doesn't work for me:

        String str = this.textBox1.Text;
        String newStr = str.Trim();
        MessageBox.Show(newStr);

        The MessageBox that appears contain the string WITH all white spaces!!! Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C# and C++!

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        ****Rickard Andersson wrote: This code doesn't work for me: It worked for me :-) Nish


        Author of the romantic comedy Summer Love and Some more Cricket [New Win] Buy it, read it and admire me :-)

        R 1 Reply Last reply
        0
        • D David Wengier

          Trim only removes leading and trailing whitespace. It doesnt remove the spaces between words etc. Is that what you mean? -- David Wengier Sonork ID: 100.14177 - Ch00k

          R Offline
          R Offline
          Rickard Andersson20
          wrote on last edited by
          #4

          hm.. what I understod from my book it was suppose to do that... but okay! Thank ya! Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C# and C++!

          1 Reply Last reply
          0
          • N Nish Nishant

            ****Rickard Andersson wrote: This code doesn't work for me: It worked for me :-) Nish


            Author of the romantic comedy Summer Love and Some more Cricket [New Win] Buy it, read it and admire me :-)

            R Offline
            R Offline
            Rickard Andersson20
            wrote on last edited by
            #5

            Nish - Native CPian wrote: It worked for me huh? Well I can compile it... but I missunderstod the use of Trim(). I thought it was suppose to remove all white spaces in the string! :) Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C# and C++!

            1 Reply Last reply
            0
            • R Rickard Andersson20

              This code doesn't work for me:

              String str = this.textBox1.Text;
              String newStr = str.Trim();
              MessageBox.Show(newStr);

              The MessageBox that appears contain the string WITH all white spaces!!! Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C# and C++!

              A Offline
              A Offline
              AndyG
              wrote on last edited by
              #6

              I think what you're looking for is Replace. String str = this.textBox1.Text; String newStr = str.Replace(" ", ""); MessageBox.Show(newStr); Andy Gaskell, MCSD MCDBA

              1 Reply Last reply
              0
              • R Rickard Andersson20

                This code doesn't work for me:

                String str = this.textBox1.Text;
                String newStr = str.Trim();
                MessageBox.Show(newStr);

                The MessageBox that appears contain the string WITH all white spaces!!! Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C# and C++!

                L Offline
                L Offline
                leppie
                wrote on last edited by
                #7

                Quote frpm MSDN ( I suggest you use it :) ) String.Trim Method Removes all occurrences of a set of specified characters from the beginning and end of this instance. Overload List Removes all occurrences of white space characters from the beginning and end of this instance. public string Trim(); Removes all occurrences of a set of characters specified in a Unicode character array from the beginning and end of this instance. public string Trim(params char[]); IOW String str = this.textBox1.Text; String newStr = str.Trim(' '); // note space char MessageBox.Show(newStr); Hope this helps :)

                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