Trimming a string : String Pad Trim : String C# Examples


C# Examples » String » String Pad Trim »

 

Trimming a string









    
using  System;
using  System.Collections.Generic;
using  System.Globalization;
using  System.IO;
using  System.Text;

public  class  MainClass
{
        public  static  void  Main()
        {
                string  s1  =  "        My          ";
                Console.WriteLine(s1);
                Console.WriteLine(s1.Trim());

                string  s2  =  "__...,,  r!,..._";
                Console.WriteLine(s2);
                char[]  trimChars  =  new  char[]  {  '.',  ',',  '_'  };
                Console.WriteLine(s2.Trim(trimChars));
                Console.WriteLine(s2.TrimStart(trimChars));
                Console.WriteLine(s2.TrimEnd(trimChars));
        }

}
    
   
  
   



Output

My
My
__...,, r!,..._
 r!
 r!,..._
__...,, r!


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo String
» String Pad Trim