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()

.trim()

Scheduled Pinned Locked Moved C#
questionlearning
7 Posts 4 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.
  • W Offline
    W Offline
    wanlim0817
    wrote on last edited by
    #1

    When I test the String.Trim() function,my resource codes as follows: using System; using System.Collections.Generic; using System.Text; namespace Ch05Ex05 { class Program { static void Main(string[] args) { string myString = " This is a test. "; char[] separator = {' '}; char[] test ={ 'T', 'i' }; string[] myWords; myString = myString.Trim(test); // myWords = myString.Split(separator); foreach (char C in myString) { Console.WriteLine("{0}", C); } Console.ReadKey(); } } } The alphabet T and i should be removed ,but when I excuted my codes,It change nothing! Can you tell me why?

    CPalliniC C V 3 Replies Last reply
    0
    • W wanlim0817

      When I test the String.Trim() function,my resource codes as follows: using System; using System.Collections.Generic; using System.Text; namespace Ch05Ex05 { class Program { static void Main(string[] args) { string myString = " This is a test. "; char[] separator = {' '}; char[] test ={ 'T', 'i' }; string[] myWords; myString = myString.Trim(test); // myWords = myString.Split(separator); foreach (char C in myString) { Console.WriteLine("{0}", C); } Console.ReadKey(); } } } The alphabet T and i should be removed ,but when I excuted my codes,It change nothing! Can you tell me why?

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Trim removes occurrences only at the begin or at the end of the string (MSDN):

      String.Trim (Char[])
      Removes all occurrences of a set of characters specified in an array from
      the beginning and end of this instance.

      :)

      In testa che avete, signor di Ceprano?

      W 1 Reply Last reply
      0
      • W wanlim0817

        When I test the String.Trim() function,my resource codes as follows: using System; using System.Collections.Generic; using System.Text; namespace Ch05Ex05 { class Program { static void Main(string[] args) { string myString = " This is a test. "; char[] separator = {' '}; char[] test ={ 'T', 'i' }; string[] myWords; myString = myString.Trim(test); // myWords = myString.Split(separator); foreach (char C in myString) { Console.WriteLine("{0}", C); } Console.ReadKey(); } } } The alphabet T and i should be removed ,but when I excuted my codes,It change nothing! Can you tell me why?

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        I think you're looking for .Replace.  You can replace T with an empty string.

        Christian Graus - C++ MVP

        W 1 Reply Last reply
        0
        • CPalliniC CPallini

          Trim removes occurrences only at the begin or at the end of the string (MSDN):

          String.Trim (Char[])
          Removes all occurrences of a set of characters specified in an array from
          the beginning and end of this instance.

          :)

          W Offline
          W Offline
          wanlim0817
          wrote on last edited by
          #4

          I have got it,Thank you! I'm a new learner on C#.I come from china.Would you mind to make friends with me? I would like that you can help to improve my english and my C#.And if you want to make a journey to china,I can be you guide. MSN:wanlim0817@hotmail.com email:wanlim0817@yahoo.com.cn

          CPalliniC 1 Reply Last reply
          0
          • C Christian Graus

            I think you're looking for .Replace.  You can replace T with an empty string.

            Christian Graus - C++ MVP

            W Offline
            W Offline
            wanlim0817
            wrote on last edited by
            #5

            I have got it,Thank you! I'm a new learner on C#.I come from china.Would you mind to make friends with me? I would like that you can help to improve my english and my C#.And if you want to make a journey to china,I can be you guide. MSN:wanlim0817@hotmail.com email:wanlim0817@yahoo.com.cn

            1 Reply Last reply
            0
            • W wanlim0817

              I have got it,Thank you! I'm a new learner on C#.I come from china.Would you mind to make friends with me? I would like that you can help to improve my english and my C#.And if you want to make a journey to china,I can be you guide. MSN:wanlim0817@hotmail.com email:wanlim0817@yahoo.com.cn

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              I wiil be happy to be your friend. On the other hand, since I'm Italian, English is not my native language. Moreover I'm not that C# expertise (C++ is my native programming language...). Anyway I will happy to receive your questions... :)

              In testa che avete, signor di Ceprano?

              1 Reply Last reply
              0
              • W wanlim0817

                When I test the String.Trim() function,my resource codes as follows: using System; using System.Collections.Generic; using System.Text; namespace Ch05Ex05 { class Program { static void Main(string[] args) { string myString = " This is a test. "; char[] separator = {' '}; char[] test ={ 'T', 'i' }; string[] myWords; myString = myString.Trim(test); // myWords = myString.Split(separator); foreach (char C in myString) { Console.WriteLine("{0}", C); } Console.ReadKey(); } } } The alphabet T and i should be removed ,but when I excuted my codes,It change nothing! Can you tell me why?

                V Offline
                V Offline
                venuvista
                wrote on last edited by
                #7

                you can use string builder or you can use the replace function it will repalce the letter T with an empt space

                venu gopal

                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