String Trim() - C# Tutorial
C# Course / Strings / String Trim()

String Trim()

BLUF: Mastering String Trim() is essential for building robust applications with the .NET ecosystem. This tutorial provides clear explanations and practical examples to help you understand and apply this C# concept.
Enterprise Development Tip: String Trim()

C# is a powerful, modern language for enterprise solutions. Discover how String Trim() enhances your development workflow in the guide below.

The Trim method in C# is employed to eliminate any white-space characters at the beginning and end of the current String instance.

Signature

Example

public string Trim()
public string Trim(params Char[])

Parameter

The initial function does not require any arguments, while the subsequent function accepts a character array as its parameter.

Return

It returns a string.

C# String Trim Method Example

Example

using System; 
    	
    public class StringExample  
    {  
        public static void Main(string[] args)  
        {  
           string s1 = "Hello C#";
           string s2 = s1.Trim();
           Console.WriteLine(s2);
        }  
    }

Output:

Output

Hello C#

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience