In ASP.Net, C# TrimEnd String Function enables you to remove the unwanted or special characters at the end of the specified string. C# TrimEnd String Function takes one parameter of Char [ ] array type. You can pass the array of special characters to the TrimEnd function to remove the specified characters from the end of the string. It traverse the string from its right end i.e. start point from its character at last index and removes the special characters specified in the char [ ] array.
string strText = "\":ASP.Net \"C#\" TrimEnd Function:\"";
char[] specialChars = new char[] { '"', ':' };
Response.Write(strText + "<br />");
Response.Write(strText.TrimEnd(specialChars) + "<br />");
Output:
":ASP.Net "C#" TrimEnd Function:"
":ASP.Net "C#" TrimEnd Function
In the above example of ASP.Net C# TrimEnd string function, two outputs show the original string and trimmed string. Second string has been retrieved without any special character at the end coz C# TrimEnd string function removed the chars specified in the char [ ] array. But special Chars at the beginning of the string are not removed coz TrimEnd function removes the special chars only from the end that’s why starting and in between string special chars are not being removed. You can use the ASP.Net C# TrimStart string function to remove the special chars at the beginning of the specified string.
Be the first to rate this post
Tags: asp.net 2.0, c#, c# trimend string function, asp.net string function, asp.net examples, asp.net trimend string function, c# trimend string, c# split, c# replace, c# indexof, c# trim, c# lastindexof, c# remove, c# trimend, c# trimstart, c# char array
10/11/2008 3:41:19 AM