Remove extra spaces from string in C#

Strings are commonly used in C#. Sometimes string can contain unwanted spaces in beginning or at end. To remove such spaces we use Trim method.

This method removes extra spaces from start and end of string. Return type of this method is string.

stringFruit = "  Apple  ";
Fruit = Fruit.Trim();
Console.WriteLine(Fruit);

Output


Apple

Comments

Popular posts from this blog

Check if ViewBag is null or doesn't exist

Using Progress Bar In C#

Jquery serer side datatables in asp.net