Re: trim(string) vs string.trim
- From: "Branco Medeiros" <branco.medeiros@xxxxxxxxx>
- Date: 21 Aug 2006 12:34:41 -0700
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.
.
- Follow-Ups:
- Re: trim(string) vs string.trim
- From: Tom Shelton
- Re: trim(string) vs string.trim
- From: Terry Olsen
- Re: trim(string) vs string.trim
- References:
- trim(string) vs string.trim
- From: Terry Olsen
- trim(string) vs string.trim
- Prev by Date: Re: how to display a label only a while?
- Next by Date: Re: how to display a label only a while?
- Previous by thread: Re: trim(string) vs string.trim
- Next by thread: Re: trim(string) vs string.trim
- Index(es):
Relevant Pages
|