Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




Trim() - Method


Trim() Method


The Trim() Method is used to remove any unwanted character from the String.


Example :



public class MyApplication
{
    public static void Main(string[] args)
    {
        string x = "   Hello  ";
	    string y = x.Trim();
	
        System.Console.WriteLine(y);    		 	
    }
}


Output :



  Hello

In the above code, we have declared a String ' Hello ' with leading and trailing spaces.


string x = "   Hello  ";
C_Sharp


Then we have used the Trim() function to remove any unwanted spaces from beginning and end.


string y = x.Trim();
C_Sharp


Unwanted spaces are stripped out of it.