Re: trim(string) vs string.trim
- From: "Terry Olsen" <tolsen64@xxxxxxxxxxx>
- Date: Mon, 21 Aug 2006 19:30:24 -0600
Yes, after all the input, I have decided to leave it as String=Trim(String)
"Branco Medeiros" <branco.medeiros@xxxxxxxxx> wrote in message
news:1156188881.224330.253450@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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.
.
- References:
- trim(string) vs string.trim
- From: Terry Olsen
- Re: trim(string) vs string.trim
- From: Branco Medeiros
- trim(string) vs string.trim
- Prev by Date: Organize and Print CSV data
- Next by Date: Re: Organize and Print CSV data
- Previous by thread: Re: trim(string) vs string.trim
- Next by thread: Re: trim(string) vs string.trim
- Index(es):
Relevant Pages
|