Use the PadLeft() and PadRight() methods to align strings : String « String « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » String » String 
5.1.17.Use the PadLeft() and PadRight() methods to align strings
using System;

class MainClass
{

  public static void Main()
  {
    string[] myStrings = {"To""be""or""not""to""be"};
    string myString = String.Join(".", myStrings);   
    
    string myString14 = '(' + myString.PadLeft(20')';
    Console.WriteLine("'(' + myString.PadLeft(20) + ')' = " + myString14);
    string myString15 = '(' + myString.PadLeft(20'.'')';
    Console.WriteLine("'(' + myString.PadLeft(20, '.') = " + myString15);
    string myString16 = '(' + myString.PadRight(20')';
    Console.WriteLine("'(' + myString.PadRight(20) + ')' = " + myString16);
    string myString17 = '(' + myString.PadRight(20'.'')';
    Console.WriteLine("'(' + myString.PadRight(20, '.') + ')' = " + myString17);

  }

}
'(' + myString.PadLeft(20) + ')' = (  To.be.or.not.to.be)
'(' + myString.PadLeft(20, '.') = (..To.be.or.not.to.be)
'(' + myString.PadRight(20) + ')' = (To.be.or.not.to.be  )
'(' + myString.PadRight(20, '.') + ')' = (To.be.or.not.to.be..)
5.1.String
5.1.1.Declaration of string
5.1.2.String is object
5.1.3.String are immutable
5.1.4.Empty string
5.1.5.Display all the characters in myString using a for loop
5.1.6.Use Indexer to reference chars in a string
5.1.7.Use the Compare() method to compare strings
5.1.8.Use the Concat() method to concatenate strings
5.1.9.Use the addition operator (+) to concatenate strings
5.1.10.Use the Copy() method to copy a string
5.1.11.Use the Equals() method and equality operator to check if two strings are equal
5.1.12.Use the Format() method to format a string
5.1.13.Use the Join() method to join strings
5.1.14.Use the Split() method to split strings
5.1.15.Use the IndexOfAny() and LastIndexOfAny() methods to search for character arrays in a string
5.1.16.Use the Insert(), Remove(), and Replace() methods to modify strings
5.1.17.Use the PadLeft() and PadRight() methods to align strings
5.1.18.Use the Trim(), TrimStart(), and TrimEnd() methods to trim strings
5.1.19.Use the Substring() method to retrieve substrings
5.1.20.Working with Strings
5.1.21.Error; string Is Immutable
5.1.22.Basic String functionality
5.1.23.Is String Interned
5.1.24.Demonstrates the String.Normalize method and the String.IsNormalized method
5.1.25.Whether a string is successfully normalized to various normalization forms.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.