Check if variable is empty

S

Shapper

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
 
L

Lucas Tam

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) <> ""
 
W

William F. Robertson, Jr.

You could check the data inside the cookie.

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

HTH,

bill
 
G

Guest

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!
***************************
 
S

Shapper

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
 
W

William F. Robertson, Jr.

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top