Trimming a string: trim start, trim end and trim chars : String Pad Trim « String « C# / CSharp Tutorial






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));
    }

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








5.16.String Pad Trim
5.16.1.String PadLeft and PadRight
5.16.2.String: trim
5.16.3.String: PadLeft/Right with character
5.16.4.String: Pad on right with #s
5.16.5.String: Trim #s
5.16.6.Trimming a string: trim start, trim end and trim chars