CSharp - String String trim

Introduction

TrimStart and TrimEnd remove specified characters from the beginning or end of a string.

Trim method does both.

By default, these functions remove whitespace characters including spaces, tabs, new lines, and Unicode variations of these.

Demo

using System;
class MainClass/* w  w  w .  j a  v a  2 s  .c o m*/
{
    public static void Main(string[] args)
    {
        string s = "  abc \t\r\n ";
        Console.WriteLine(s.Length);
        Console.WriteLine(s.Trim().Length);

    }
}

Result

Example