String PadLeft and PadRight : String Pad Trim : String C# Examples


C# Examples » String » String Pad Trim »

 

String PadLeft and PadRight









    
using  System;    
    
class  MainClass  {    
    public  static  void  Main()  {    
        string  str  =  "test";  
  
        Console.WriteLine("Original  string:  "  +  str);  
          
        //  Pad  on  left  with  spaces.  
        str  =  str.PadLeft(10);  
        Console.WriteLine("|"  +  str  +  "|");  
  
        //  Pad  on  right  with  spaces.  
        str  =  str.PadRight(20);  
        Console.WriteLine("|"  +  str  +  "|");  
  
    }  
}
    
   
  
   



Output

Original string: test
|      test|
|      test          |


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo String
» String Pad Trim