Everyday I Learn - String.Trim vs Trim(string)

posted on Wednesday, August 20, 2008 2:00 PM

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.

i.e.
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


No comments posted yet.
Post Comment
Title *
Name *
Email
Url
Comment *
Please add 6 and 5 and type the answer here:

About Me

An engineer by training and a software developer at heart. My techniques and approaches meld engineering approaches with software technology.

Core to these principles is a systematic approach to the development of software with a strong lifecycle and process management emphasis through adoption of mature technologies.

Ten years designing heavy structural steel and concrete structures and 12 years in the software development profession have embedded strong project management and business knowledge in my approaches.

Subscribe to Rss Feed


Follow me on twitter @dyardy