The Trim function implemented as a method of the Microsoft.VisualBasic
namespace and acts identically to the VB6 Trim function. I.E., It returns a
string containing a copy of a specified string with no leading or trailing
spaces.
The Trim method is implemented as a method of the System.String class and it
returns a new string equivalent to the specified string after white space
characters are removed from the beginning and end. In addition, this method
has an overload where one can specify which character(s) should be removed.
Calling the Trim function is the same as VB6:
_s = Trim(_s)
whereas the Trim method operates on a string instance:
_s = _s.Trim()
Because white space comprises characters in addition to the space character,
if you want to remove only spaces then you must call the the Trim function
or the overloaded Trim method with a parameter of " "c.
I have run tests that show that using the Trim method gives a marginal
performance saving, and I stress the word marginal. Any other evidence I
have heard or read on the performance of the Trim function over the Trim
method or vice-versa is purely anecdotal.
"Sascha Herpers" <he*****@wiso.uni-koeln.de> wrote in message
news:a5**************************@posting.google.c om...
Hi,
what is the difference between the trim function and the trim
String-member?
As far as I see it, both return the trimmed string and leave the
original string unaltered.
Is any of the two faster? Is there a general rule/opinion to prefere
members over functions?
Thanks for any hint.
Sascha