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/*from w  ww.  ja  v a 2  s. c  om*/
{
    public static void Main(string[] args)
    {
        string s = "  abc \t\r\n ";
        Console.WriteLine(s.Length);
        Console.WriteLine(s.Trim().Length);

    }
}

Result

Example