![]() |
VOOZH | about |
In C#, TrimStart() & TrimEnd() are the string methods. TrimStart() method is used to remove the occurrences of a set of characters specified in an array from the starting of the current String object. TrimEnd() method is used to remove the occurrences of a set of characters specified in an array from the ending of the current String object.
Syntax for TrimStart() Method :
public string TrimStart(params char[] trimChars)
Syntax for TrimEnd() Method :
public string TrimEnd(params char[] trimChars)
Explanation: Both the method will take an array of Unicode characters or null as a parameter. Null is because of params keyword. And the return type value for both the methods is System.String.
Below are the programs to demonstrate the above methods :
Before: *****0000abc000**** abc -GFG- GeeksforGeeks After: abc000**** abc -GFG- forGeeks
Before: *****0000abc000**** abc -GFG- GeeksforGeeks After: *****0000abc abc -GFG- Geeksfor
Note: If no parameter will pass in both the method's arguments list then Null , TAB, Carriage Return and White Space will automatically remove from starting(for TrimStart() method) and ending(for TrimEnd() method) from the current string object. And If any parameter will pass to both the methods then the only specified character(which passed as arguments) will removed from the current string object. Null, TAB, Carriage Return, and White Space will not remove automatically if they are not specified in the arguments list of both the methods.
References: