String.Trim method - Removes all occurrences of white space characters from the beginning and end of this instance.

Trim(var) method - returns a string with no leading or trailing spaces

Yes, there is a difference between these.  The String.Trim will remove any non-visible characters such as line feeds and carriage returns.

How I came across this was as a result of an odd exception I am getting from an application.  Randomly the NameValueCollection after a postback will have an appended or prepended line feed.

hidCustomerID: -1
hidCustomerNo: 0
hidCurrent: True

hidOrderID: -1

When the codebehind tries to ctype(hidCurrent, Boolean) it recieves True or False with additional hidden line feeds.  This is within an ASP.NET 2.x web application.  I have yet to find the source of this problem but I am hoping the String.Trim() will help me out here.  If you have any ideas please let me know what may be going on here.


Comments are closed

About Us

Web/Mobile Solutions

Useful Links

Our Contacts

Cincinnati, OH 45069