Re: trim(string) vs string.trim




Terry Olsen wrote:
I have an app that makes decisions based on string content. I need to make
sure that a string does not contain only spaces or newlines. I am using the
syntax 'Trim(String)" and it works fine. I thought I'd change it to the VB
.NET method "String.Trim" but that throws an object exception.

Which brings the question: is it compliant to use Trim(String), or is it
more within etiquette to use If Not String Is Nothing Then String.Trim?

The advantage of using Trim instead of String.Trim is exactly that Trim
will recognize when a String is Nothing and return "" as a result. If
this is the logic of your application, then instead of doing:

If SomeStr Is Nothing then
Value = ""
'I personally preffer Value = String.Empty
Else
Value = String.Trim
End If

you could spare the effort and just use Value = Trim(SomeStr)

On the other hand, if you must know when a passed string is invalid
(Nothing) then probably checking for Nothing before calling String.Trim
is the way to go.

Regards,

Branco.

.



Relevant Pages

  • Re: Fortran
    ... it didn't implement a working TRIM() in F77. ... CHARACTER*80 STRING ... EXTERNAL MYTRIM ... STRING = 'alongword' ...
    (comp.lang.fortran)
  • Re: Fortran
    ... it didn't implement a working TRIM() in F77. ... CHARACTER*10 MYTRIM ... STRING = 'hello' ... STRING = 'alongword' ...
    (comp.lang.fortran)
  • Trim() function chain-link. Please Help me...
    ... income dependent on the number in the household. ... that is I used the Trim() function... ... wrong that is preventing my string of codes to not recognize the other ... then move result to Cell C53 ...
    (microsoft.public.excel.programming)
  • Re: FAQ Topic - How do I trim whitespace - trim/trimRight/trimLeft (2007-12-25)
    ... though the Subject refers to whitespace the answer refers only to ... the word used alone is thus not ideal for describing what trim ... Most string manipulations are best done by using Regular Expressions. ...
    (comp.lang.javascript)
  • Re: Question mark before node?
    ... Also it may be a good idea to remove the map ... the returned xml document has the xml declaration in ... I originally was not using a map, and was trying to trim the values ... string of the length of the field to the Xml document. ...
    (microsoft.public.biztalk.general)