trim(string) vs string.trim

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Terry Olsen

    trim(string) vs string.trim

    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.Tri m" 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?


  • Jared

    #2
    RE: trim(string) vs string.trim

    Terry,
    You should always check your parameters/variables for null references
    whenever there is doubt.

    You can use the negating logic if you prefer, its just not as straight
    forward (it is here, I just avoid negating logic whenever possible)
    If Not Is Nothing Then
    stringVariable = stringVariable. Trim
    End If

    If stringVariable is nothing then
    stringVariable = string.empty
    Else
    stringVariable = stringVariable. Trim
    End If

    Whatever you decide, just be consistient.

    "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.Tri m" 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?
    >
    >
    >

    Comment

    • Claes Bergefall

      #3
      Re: trim(string) vs string.trim

      Don't forget the new IsNot operator that was introduced in 2.0. It's a bit
      easier to read imo.

      If stringVariable IsNot Nothing Then
      stringVariable = stringVariable. Trim
      End If

      /claes

      "Jared" <Jared@discussi ons.microsoft.c omwrote in message
      news:246C89B1-5305-441E-A74C-263551BA6ECC@mi crosoft.com...
      Terry,
      You should always check your parameters/variables for null references
      whenever there is doubt.
      >
      You can use the negating logic if you prefer, its just not as straight
      forward (it is here, I just avoid negating logic whenever possible)
      If Not Is Nothing Then
      stringVariable = stringVariable. Trim
      End If
      >
      If stringVariable is nothing then
      stringVariable = string.empty
      Else
      stringVariable = stringVariable. Trim
      End If
      >
      Whatever you decide, just be consistient.
      >
      "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.Tri m" 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?
      >>
      >>
      >>

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: trim(string) vs string.trim

        Claes,
        Don't forget the new IsNot operator that was introduced in 2.0. It's a bit
        easier to read imo.
        Maybe for native English people, I find it terrible to read.

        Cor

        "Claes Bergefall" <louplou@nospam .nospamschreef in bericht
        news:%23SQqlsSx GHA.4752@TK2MSF TNGP02.phx.gbl. ..
        Don't forget the new IsNot operator that was introduced in 2.0. It's a bit
        easier to read imo.
        >
        If stringVariable IsNot Nothing Then
        stringVariable = stringVariable. Trim
        End If
        >
        /claes
        >
        "Jared" <Jared@discussi ons.microsoft.c omwrote in message
        news:246C89B1-5305-441E-A74C-263551BA6ECC@mi crosoft.com...
        >Terry,
        >You should always check your parameters/variables for null references
        >whenever there is doubt.
        >>
        >You can use the negating logic if you prefer, its just not as straight
        >forward (it is here, I just avoid negating logic whenever possible)
        >If Not Is Nothing Then
        > stringVariable = stringVariable. Trim
        >End If
        >>
        >If stringVariable is nothing then
        > stringVariable = string.empty
        >Else
        > stringVariable = stringVariable. Trim
        >End If
        >>
        >Whatever you decide, just be consistient.
        >>
        >"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.Tri m" 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?
        >>>
        >>>
        >>>
        >
        >

        Comment

        • Branco Medeiros

          #5
          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.Tri m" 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.

          Comment

          • Terry Olsen

            #6
            Re: trim(string) vs string.trim

            Yes, after all the input, I have decided to leave it as String=Trim(Str ing)

            "Branco Medeiros" <branco.medeiro s@gmail.comwrot e in message
            news:1156188881 .224330.253450@ m79g2000cwm.goo glegroups.com.. .
            >
            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.Tri m" 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.
            >

            Comment

            • Phill W.

              #7
              Re: trim(string) vs string.trim

              Cor Ligthert [MVP] wrote:
              Claes,
              >
              >Don't forget the new IsNot operator that was introduced in 2.0. It's a bit
              >easier to read imo.
              >
              Maybe for native English people, I find it terrible to read.
              Cor,

              I *am* English and I think the "Eye-Snot" operator is appalling.

              I've been using something like

              Function IsSomething( ByVal oThing As Object ) As Boolean
              Return Not (oThing Is Nothing )
              End Function

              (in various guises) for more years than I like to think about and have
              no intention of changing.

              OK, there's an overhead in calling a function, but any half-decent
              compiler would optimise that out.

              Regards,
              Phill W.

              Comment

              • Cor Ligthert [MVP]

                #8
                Re: trim(string) vs string.trim

                Phill,

                In your sample it is a boolean.

                My is told that English people seem to use IsNot Nothing when it is
                Something.

                I prefer "something" because I hate those possible constructions as it is in
                VB.Net as
                If Not (Not ObjectAddress IsNot Nothing) what is a valid instruction to
                return a boolean if that address is something.

                But as me is told is this for English people easy readable.

                Not all spoken language are always algabraic correct do you know.

                Cor

                "Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kschreef in bericht
                news:ecetn2$p2f $1@south.jnrs.j a.net...
                Cor Ligthert [MVP] wrote:
                >Claes,
                >>
                >>Don't forget the new IsNot operator that was introduced in 2.0. It's a
                >>bit easier to read imo.
                >>
                >Maybe for native English people, I find it terrible to read.
                >
                Cor,
                >
                I *am* English and I think the "Eye-Snot" operator is appalling.
                >
                I've been using something like
                >
                Function IsSomething( ByVal oThing As Object ) As Boolean
                Return Not (oThing Is Nothing )
                End Function
                >
                (in various guises) for more years than I like to think about and have no
                intention of changing.
                >
                OK, there's an overhead in calling a function, but any half-decent
                compiler would optimise that out.
                >
                Regards,
                Phill W.

                Comment

                • Terry Olsen

                  #9
                  Re: trim(string) vs string.trim

                  Ok, not being formally trained in the art of coding, what exactly is
                  apalling about IsNot? It seems like a perfectly valid and logical option to
                  me. Your method is like making 3 left turns to get to the store when a
                  single right turn would have gotten you there, simply because you don't like
                  right turns.

                  "Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
                  news:ecetn2$p2f $1@south.jnrs.j a.net...
                  Cor Ligthert [MVP] wrote:
                  >Claes,
                  >>
                  >>Don't forget the new IsNot operator that was introduced in 2.0. It's a
                  >>bit easier to read imo.
                  >>
                  >Maybe for native English people, I find it terrible to read.
                  >
                  Cor,
                  >
                  I *am* English and I think the "Eye-Snot" operator is appalling.
                  >
                  I've been using something like
                  >
                  Function IsSomething( ByVal oThing As Object ) As Boolean
                  Return Not (oThing Is Nothing )
                  End Function
                  >
                  (in various guises) for more years than I like to think about and have no
                  intention of changing.
                  >
                  OK, there's an overhead in calling a function, but any half-decent
                  compiler would optimise that out.
                  >
                  Regards,
                  Phill W.

                  Comment

                  • Claes Bergefall

                    #10
                    Re: trim(string) vs string.trim

                    "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
                    news:uMl80cTxGH A.4972@TK2MSFTN GP05.phx.gbl...
                    Claes,
                    >
                    >Don't forget the new IsNot operator that was introduced in 2.0. It's a
                    >bit easier to read imo.
                    >
                    Maybe for native English people, I find it terrible to read.
                    >
                    Cor
                    >
                    Well, I'm Swedish and I find it a lot better than using 'If Not ... Is
                    Nothing...'. That just looks weird. Until they add support for 'If ... Is
                    Something' I'm sticking with the IsNot operator

                    /claes


                    Comment

                    • Claes Bergefall

                      #11
                      Re: trim(string) vs string.trim


                      "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
                      news:eutCIuexGH A.980@TK2MSFTNG P04.phx.gbl...
                      Phill,
                      >
                      In your sample it is a boolean.
                      >
                      My is told that English people seem to use IsNot Nothing when it is
                      Something.
                      >
                      I prefer "something" because I hate those possible constructions as it is
                      in VB.Net as
                      If Not (Not ObjectAddress IsNot Nothing) what is a valid instruction to
                      return a boolean if that address is something.
                      Now you're abusing the language :-)
                      (And you failed my code review ;-))

                      The above is eqvivalent to:
                      If ObjectAddress IsNot Nothing
                      or
                      If Not ObjectAddress Is Nothing

                      Personally I find the first form easier to read (and I'm not English). A
                      'Something' keyword would be nice though...

                      /claes


                      Comment

                      • Brian Tkatch

                        #12
                        Re: trim(string) vs string.trim


                        Cor Ligthert [MVP] wrote:
                        Claes,
                        >
                        Don't forget the new IsNot operator that was introduced in 2.0. It's a bit
                        easier to read imo.
                        >
                        Maybe for native English people, I find it terrible to read.
                        >
                        Cor
                        >
                        "Claes Bergefall" <louplou@nospam .nospamschreef in bericht
                        news:%23SQqlsSx GHA.4752@TK2MSF TNGP02.phx.gbl. ..
                        Don't forget the new IsNot operator that was introduced in 2.0. It's a bit
                        easier to read imo.

                        If stringVariable IsNot Nothing Then
                        stringVariable = stringVariable. Trim
                        End If

                        /claes

                        "Jared" <Jared@discussi ons.microsoft.c omwrote in message
                        news:246C89B1-5305-441E-A74C-263551BA6ECC@mi crosoft.com...
                        Terry,
                        You should always check your parameters/variables for null references
                        whenever there is doubt.
                        >
                        You can use the negating logic if you prefer, its just not as straight
                        forward (it is here, I just avoid negating logic whenever possible)
                        If Not Is Nothing Then
                        stringVariable = stringVariable. Trim
                        End If
                        >
                        If stringVariable is nothing then
                        stringVariable = string.empty
                        Else
                        stringVariable = stringVariable. Trim
                        End If
                        >
                        Whatever you decide, just be consistient.
                        >
                        "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.Tri m" 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 term closely follows SQL. Is SQL, the IS operator supports NOT, as
                        opposed to =, which does not support NOT.

                        Thus A = B and NOT (A = B), but A NOT = B is invalid.

                        However, IS does support it so: A IS NULL, NOT A IS NULL, and A IS NOT
                        NULL, are all valid.

                        Personally, i welcome the IsNot operator. Being "Is" is a special case
                        (checking the meta-data as opposed to the data itself) having it's own
                        negativity operator is fine, especially when it sort of follows a well
                        known SQL standard (for checking meta-data).

                        B.

                        Comment

                        • Cor Ligthert [MVP]

                          #13
                          Re: trim(string) vs string.trim

                          Brian, Terry, Claes,

                          The "IsNot" is one of my Carthago's.

                          Even this would be better in my idea.

                          \\\
                          Dim IsNotYetInstanc ed As Object
                          Dim myarray As ArrayList
                          If myarray Is IsNotYetInstanc ed Then
                          MessageBox.Show ("I am not something")
                          End If
                          ///

                          This can every kid make, the same as probably is done.

                          With Jay I would like if there was something as "Something" to show that the
                          address part of an object was not empty.

                          Cor


                          "Brian Tkatch" <Maxwell_Smart@ ThePentagon.com schreef in bericht
                          news:1156258659 .903839.259580@ p79g2000cwp.goo glegroups.com.. .
                          >
                          Cor Ligthert [MVP] wrote:
                          >Claes,
                          >>
                          Don't forget the new IsNot operator that was introduced in 2.0. It's a
                          bit
                          easier to read imo.
                          >>
                          >Maybe for native English people, I find it terrible to read.
                          >>
                          >Cor
                          >>
                          >"Claes Bergefall" <louplou@nospam .nospamschreef in bericht
                          >news:%23SQqlsS xGHA.4752@TK2MS FTNGP02.phx.gbl ...
                          Don't forget the new IsNot operator that was introduced in 2.0. It's a
                          bit
                          easier to read imo.
                          >
                          If stringVariable IsNot Nothing Then
                          stringVariable = stringVariable. Trim
                          End If
                          >
                          /claes
                          >
                          "Jared" <Jared@discussi ons.microsoft.c omwrote in message
                          news:246C89B1-5305-441E-A74C-263551BA6ECC@mi crosoft.com...
                          >Terry,
                          >You should always check your parameters/variables for null references
                          >whenever there is doubt.
                          >>
                          >You can use the negating logic if you prefer, its just not as straight
                          >forward (it is here, I just avoid negating logic whenever possible)
                          >If Not Is Nothing Then
                          > stringVariable = stringVariable. Trim
                          >End If
                          >>
                          >If stringVariable is nothing then
                          > stringVariable = string.empty
                          >Else
                          > stringVariable = stringVariable. Trim
                          >End If
                          >>
                          >Whatever you decide, just be consistient.
                          >>
                          >"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.Tri m" 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 term closely follows SQL. Is SQL, the IS operator supports NOT, as
                          opposed to =, which does not support NOT.
                          >
                          Thus A = B and NOT (A = B), but A NOT = B is invalid.
                          >
                          However, IS does support it so: A IS NULL, NOT A IS NULL, and A IS NOT
                          NULL, are all valid.
                          >
                          Personally, i welcome the IsNot operator. Being "Is" is a special case
                          (checking the meta-data as opposed to the data itself) having it's own
                          negativity operator is fine, especially when it sort of follows a well
                          known SQL standard (for checking meta-data).
                          >
                          B.
                          >

                          Comment

                          • Jim Wooley

                            #14
                            Re: trim(string) vs string.trim

                            With extension methods in VB9, you will be able to do something like:

                            <Extension()_
                            Public Module CustomExtension s
                            <Extension() _
                            Public Function IsSomething(byV al target as Object) as Boolean
                            Return Not target Is Nothing
                            End Function
                            End Module

                            Then to consume it, as long as your CustomExtension s are in scope, you will
                            be able to take any object and call it's extension method IsSomething as
                            follows:

                            dim foo as Object
                            If foo.IsSomething
                            'Do Work
                            End If

                            Note, VB9 is still under development and the syntax is subject to change
                            before release in Orcas, but it does give you an idea of what you can do.
                            Be careful, extension methods can be is a very big gun, with which you can
                            easily shoot yourself in the foot.

                            Jim Wooley

                            Brian, Terry, Claes,
                            >
                            The "IsNot" is one of my Carthago's.
                            >
                            Even this would be better in my idea.
                            >
                            \\\
                            Dim IsNotYetInstanc ed As Object
                            Dim myarray As ArrayList
                            If myarray Is IsNotYetInstanc ed Then
                            MessageBox.Show ("I am not something")
                            End If
                            ///
                            This can every kid make, the same as probably is done.
                            >
                            With Jay I would like if there was something as "Something" to show
                            that the address part of an object was not empty.
                            >
                            Cor
                            >
                            "Brian Tkatch" <Maxwell_Smart@ ThePentagon.com schreef in bericht
                            news:1156258659 .903839.259580@ p79g2000cwp.goo glegroups.com.. .
                            >
                            >Cor Ligthert [MVP] wrote:
                            >>
                            >>Claes,
                            >>>
                            >>>Don't forget the new IsNot operator that was introduced in 2.0.
                            >>>It's a
                            >>>bit
                            >>>easier to read imo.
                            >>Maybe for native English people, I find it terrible to read.
                            >>>
                            >>Cor
                            >>>
                            >>"Claes Bergefall" <louplou@nospam .nospamschreef in bericht
                            >>news:%23SQqls SxGHA.4752@TK2M SFTNGP02.phx.gb l...
                            >>>
                            >>>Don't forget the new IsNot operator that was introduced in 2.0.
                            >>>It's a
                            >>>bit
                            >>>easier to read imo.
                            >>>If stringVariable IsNot Nothing Then
                            >>>stringVariab le = stringVariable. Trim
                            >>>End If
                            >>>/claes
                            >>>>
                            >>>"Jared" <Jared@discussi ons.microsoft.c omwrote in message
                            >>>news:246C89B 1-5305-441E-A74C-263551BA6ECC@mi crosoft.com...
                            >>>>
                            >>>>Terry,
                            >>>>You should always check your parameters/variables for null
                            >>>>reference s
                            >>>>whenever there is doubt.
                            >>>>You can use the negating logic if you prefer, its just not as
                            >>>>straight
                            >>>>forward (it is here, I just avoid negating logic whenever
                            >>>>possible)
                            >>>>If Not Is Nothing Then
                            >>>>stringVaria ble = stringVariable. Trim
                            >>>>End If
                            >>>>If stringVariable is nothing then
                            >>>>stringVaria ble = string.empty
                            >>>>Else
                            >>>>stringVaria ble = stringVariable. Trim
                            >>>>End If
                            >>>>Whatever you decide, just be consistient.
                            >>>>>
                            >>>>"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.Tri m" 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.Tri m?
                            >The term closely follows SQL. Is SQL, the IS operator supports NOT,
                            >as opposed to =, which does not support NOT.
                            >>
                            >Thus A = B and NOT (A = B), but A NOT = B is invalid.
                            >>
                            >However, IS does support it so: A IS NULL, NOT A IS NULL, and A IS
                            >NOT NULL, are all valid.
                            >>
                            >Personally, i welcome the IsNot operator. Being "Is" is a special
                            >case (checking the meta-data as opposed to the data itself) having
                            >it's own negativity operator is fine, especially when it sort of
                            >follows a well known SQL standard (for checking meta-data).
                            >>
                            >B.
                            >>
                            Jim Wooley



                            Comment

                            • Cor Ligthert [MVP]

                              #15
                              Re: trim(string) vs string.trim

                              Jim,

                              I don't want IsSomething, that are solutions thought by developers inside
                              their own community closing the doors for the world. The same for me as not
                              using the "+" in programs but creating a function for that IsPlus(ValueA,
                              ValueB).

                              It has to be

                              If myObjectAdress is Something

                              Cor

                              "Jim Wooley" <jimNOSPAMwoole y@hotmail.comsc hreef in bericht
                              news:24f81e8fbd 448c894aaa4527f 5f@msnews.micro soft.com...
                              With extension methods in VB9, you will be able to do something like:
                              >
                              <Extension()_
                              Public Module CustomExtension s
                              <Extension() _
                              Public Function IsSomething(byV al target as Object) as Boolean
                              Return Not target Is Nothing
                              End Function
                              End Module
                              >
                              Then to consume it, as long as your CustomExtension s are in scope, you
                              will be able to take any object and call it's extension method IsSomething
                              as follows:
                              >
                              dim foo as Object
                              If foo.IsSomething
                              'Do Work
                              End If
                              >
                              Note, VB9 is still under development and the syntax is subject to change
                              before release in Orcas, but it does give you an idea of what you can do.
                              Be careful, extension methods can be is a very big gun, with which you can
                              easily shoot yourself in the foot.
                              >
                              Jim Wooley

                              >
                              >Brian, Terry, Claes,
                              >>
                              >The "IsNot" is one of my Carthago's.
                              >>
                              >Even this would be better in my idea.
                              >>
                              >\\\
                              >Dim IsNotYetInstanc ed As Object
                              >Dim myarray As ArrayList
                              >If myarray Is IsNotYetInstanc ed Then
                              >MessageBox.Sho w("I am not something")
                              >End If
                              >///
                              >This can every kid make, the same as probably is done.
                              >>
                              >With Jay I would like if there was something as "Something" to show
                              >that the address part of an object was not empty.
                              >>
                              >Cor
                              >>
                              >"Brian Tkatch" <Maxwell_Smart@ ThePentagon.com schreef in bericht
                              >news:115625865 9.903839.259580 @p79g2000cwp.go oglegroups.com. ..
                              >>
                              >>Cor Ligthert [MVP] wrote:
                              >>>
                              >>>Claes,
                              >>>>
                              >>>>Don't forget the new IsNot operator that was introduced in 2.0.
                              >>>>It's a
                              >>>>bit
                              >>>>easier to read imo.
                              >>>Maybe for native English people, I find it terrible to read.
                              >>>>
                              >>>Cor
                              >>>>
                              >>>"Claes Bergefall" <louplou@nospam .nospamschreef in bericht
                              >>>news:%23SQql sSxGHA.4752@TK2 MSFTNGP02.phx.g bl...
                              >>>>
                              >>>>Don't forget the new IsNot operator that was introduced in 2.0.
                              >>>>It's a
                              >>>>bit
                              >>>>easier to read imo.
                              >>>>If stringVariable IsNot Nothing Then
                              >>>>stringVaria ble = stringVariable. Trim
                              >>>>End If
                              >>>>/claes
                              >>>>>
                              >>>>"Jared" <Jared@discussi ons.microsoft.c omwrote in message
                              >>>>news:246C89 B1-5305-441E-A74C-263551BA6ECC@mi crosoft.com...
                              >>>>>
                              >>>>>Terry,
                              >>>>>You should always check your parameters/variables for null
                              >>>>>referenc es
                              >>>>>whenever there is doubt.
                              >>>>>You can use the negating logic if you prefer, its just not as
                              >>>>>straight
                              >>>>>forward (it is here, I just avoid negating logic whenever
                              >>>>>possible )
                              >>>>>If Not Is Nothing Then
                              >>>>>stringVari able = stringVariable. Trim
                              >>>>>End If
                              >>>>>If stringVariable is nothing then
                              >>>>>stringVari able = string.empty
                              >>>>>Else
                              >>>>>stringVari able = stringVariable. Trim
                              >>>>>End If
                              >>>>>Whatever you decide, just be consistient.
                              >>>>>>
                              >>>>>"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.Tri m" 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.Tr im?
                              >>The term closely follows SQL. Is SQL, the IS operator supports NOT,
                              >>as opposed to =, which does not support NOT.
                              >>>
                              >>Thus A = B and NOT (A = B), but A NOT = B is invalid.
                              >>>
                              >>However, IS does support it so: A IS NULL, NOT A IS NULL, and A IS
                              >>NOT NULL, are all valid.
                              >>>
                              >>Personally, i welcome the IsNot operator. Being "Is" is a special
                              >>case (checking the meta-data as opposed to the data itself) having
                              >>it's own negativity operator is fine, especially when it sort of
                              >>follows a well known SQL standard (for checking meta-data).
                              >>>
                              >>B.
                              >>>
                              Jim Wooley

                              >
                              >

                              Comment

                              Working...