Thursday, May 23, 2013

Purpose Of Trim Function in C#.Net


It enables you to remove the unwanted characters from both beginning and ending of the string. By Default C# string trimfunction trims the white spaces from both ends of the given string. Additional parameters of the String Trim function provide the functionality to remove more than one special character from both ends of the string. C# String Function cannot remove the special characters from within the string.

Eg:

  1. strText = "\"ASP.Net \"C#\" Trim Function:\"";  
  2.   
  3. Response.Write(strText + "<br />");  
  4.   
  5. Response.Write(strText.Trim(new char[] { '"' }) + "<br />");  
  6.   
  7. char[] specialChars = new char[] { '"'':' };  
  8.   
  9. Response.Write(strText.Trim(specialChars) + "<br />");  

No comments:

Post a Comment