Using $ in some commands

  • Thread starter Thread starter Doogie
  • Start date Start date
D

Doogie

Hi,

I have a lot of old VB 6 experience and for the last several years
have been programming in C#. Now I'm going to be doing some VB.NET
development. As I'm "relearning" things so to speak, I remember I was
taught that using commands like Trim$ and LTrim$ instead of Trim and
LTrim were the better way to go (although I cannot remember why).

Does this still hold true in VB.NET?
 
nope, there are .net oriented methods in the string class now to use
instead... if it worked in C# it will work in VB.NET basically
 
Doogie said:
I remember I was
taught that using commands like Trim$ and LTrim$ instead of Trim and
LTrim were the better way to go (although I cannot remember why).

Does this still hold true in VB.NET?

No.

The reason Trim$() was preferable to Trim() was because they were both
different functions. Trim$() returned a String, Trim() returned a Variant
which was then implicitly converted to a string in your code. The Variant
approach used additional resources and was slower to execute.

In VB.NET they have tidied all of this up now, and there is a single
function called Trim() which returns a String. There's no equivalent to the
Variant-returning version of the function from VB6. If you follow the
function call with the $ suffix, this will be tolerated but ignored.

Hope that helps,
 
Doogie said:
I remember I was taught that using commands like Trim$ and LTrim$
instead of Trim and LTrim were the better way to go (although I
cannot remember why).

Trim$ returned a String.
Trim returned a Variant /containing/ a String.

There were some performance benefits in /avoiding/ the Variant "wrapper".
Does this still hold true in VB.NET?

Nope! All the String functions now return Strings and Variants are Dead
and Buried.

HTH,
Phill W.
 
Smokey Grindle said:
nope, there are .net oriented methods in the string class now to use
instead...

There is no reason to use the 'String' class' methods instead of the
'Strings' module's functions. These functions are still fist class citizens
in VB!
 
Back
Top