Check if variable is empty

Discussion in 'ASP .Net' started by Shapper, May 16, 2005.

  1. Shapper

    Shapper Guest

    Hello,

    I am using this code line to check i a variable exists:
    If cookie Is Nothing Then
    ....

    How can I check if cookie is empty when cookie exists?

    Thanks,
    Miguel
    Shapper, May 16, 2005
    #1
    1. Advertising

  2. Shapper

    Lucas Tam Guest

    "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in news:OH0
    #:

    > Hello,
    >
    > I am using this code line to check i a variable exists:
    > If cookie Is Nothing Then
    > ...
    >
    > How can I check if cookie is empty when cookie exists?



    You can try:

    Trim(Cookie) <> ""




    --
    Lucas Tam ()
    Please delete "REMOVE" from the e-mail address when replying.
    http://members.ebay.com/aboutme/coolspot18/
    Lucas Tam, May 16, 2005
    #2
    1. Advertising

  3. You could check the data inside the cookie.

    if cookie.Values.Length == 0 then
    'the cookie is empty
    endif

    HTH,

    bill

    "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
    news:OH0%...
    > Hello,
    >
    > I am using this code line to check i a variable exists:
    > If cookie Is Nothing Then
    > ...
    >
    > How can I check if cookie is empty when cookie exists?
    >
    > Thanks,
    > Miguel
    >
    >
    >
    William F. Robertson, Jr., May 16, 2005
    #3
  4. If(Cookie.Values.Length == 0) Then
    'cookie is empty
    Else
    'cookie is not empty
    End If


    ---

    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    ***************************
    Think Outside the Box!
    ***************************

    "Shapper" wrote:

    > Hello,
    >
    > I am using this code line to check i a variable exists:
    > If cookie Is Nothing Then
    > ....
    >
    > How can I check if cookie is empty when cookie exists?
    >
    > Thanks,
    > Miguel
    >
    >
    >
    >
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN, May 16, 2005
    #4
  5. Shapper

    Shapper Guest

    Hello,

    My mistake: I gave the cookie example.

    Basically I am looking to a way to check is a String is Empty or Null.

    I know ASP.Net will have a IsEmptyOrNull Function.

    I have been reading information about this in Asp.Net 1.1 but it seems
    there are several ways to do it in relation to optimization.

    I am in this moment using the following in VB.NET:

    If myString Is Nothing Or myString = String.Empty Then
    ....

    What do you think?

    Cheers,
    Miguel


    "Cowboy (Gregory A. Beamer) - MVP" <>
    wrote in message news::

    > If(Cookie.Values.Length == 0) Then
    > 'cookie is empty
    > Else
    > 'cookie is not empty
    > End If
    >
    >
    > ---
    >
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    >
    > ***************************
    > Think Outside the Box!
    > ***************************
    >
    > "Shapper" wrote:
    >
    >
    > > Hello,
    > >
    > > I am using this code line to check i a variable exists:
    > > If cookie Is Nothing Then
    > > ....
    > >
    > > How can I check if cookie is empty when cookie exists?
    > >
    > > Thanks,
    > > Miguel
    > >
    > >
    > >
    > >
    Shapper, May 17, 2005
    #5
  6. I always check the length property of a string.

    In c# code code I use is

    string s;
    if ( s == null || s.Length == 0 )
    {

    }

    Length is a property of the string that returns much faster than comparing
    to String.Empty.

    bill


    "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
    news:O%...
    > Hello,
    >
    > My mistake: I gave the cookie example.
    >
    > Basically I am looking to a way to check is a String is Empty or Null.
    >
    > I know ASP.Net will have a IsEmptyOrNull Function.
    >
    > I have been reading information about this in Asp.Net 1.1 but it seems
    > there are several ways to do it in relation to optimization.
    >
    > I am in this moment using the following in VB.NET:
    >
    > If myString Is Nothing Or myString = String.Empty Then
    > ...
    >
    > What do you think?
    >
    > Cheers,
    > Miguel
    >
    >
    > "Cowboy (Gregory A. Beamer) - MVP" <>
    > wrote in message news::
    >
    > > If(Cookie.Values.Length == 0) Then
    > > 'cookie is empty
    > > Else
    > > 'cookie is not empty
    > > End If
    > >
    > >
    > > ---
    > >
    > > Gregory A. Beamer
    > > MVP; MCP: +I, SE, SD, DBA
    > >
    > > ***************************
    > > Think Outside the Box!
    > > ***************************
    > >
    > > "Shapper" wrote:
    > >
    > >
    > > > Hello,
    > > >
    > > > I am using this code line to check i a variable exists:
    > > > If cookie Is Nothing Then
    > > > ....
    > > >
    > > > How can I check if cookie is empty when cookie exists?
    > > >
    > > > Thanks,
    > > > Miguel
    > > >
    > > >
    > > >
    > > >

    >
    William F. Robertson, Jr., May 17, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shapper
    Replies:
    1
    Views:
    1,759
    gabe garza
    May 10, 2005
  2. John

    empty/non-empty element

    John, Jul 15, 2003, in forum: XML
    Replies:
    1
    Views:
    1,015
    Klaus Johannes Rusch
    Jul 16, 2003
  3. Lukas
    Replies:
    3
    Views:
    791
    spiff
    Nov 10, 2005
  4. Marcia Hon

    Check if a directory is empty and empty it

    Marcia Hon, Feb 8, 2004, in forum: C Programming
    Replies:
    8
    Views:
    566
    Dave Thompson
    Feb 14, 2004
  5. Brian Roberts

    empty lists vs empty generators

    Brian Roberts, May 3, 2005, in forum: Python
    Replies:
    12
    Views:
    648
    Jeremy Bowers
    May 4, 2005
Loading...

Share This Page