Sometimes we are very entangled, what is the difference between isNull, IsEmpty and the "empty string"?
IsNull ()
A Null value indicates that the variable does not contain valid data. Null differs from Empty, which indicates that the variable was uninitialized. Null is also different from a 0-length string (""), and a 0-length string often refers to an empty string.
Focus on using the IsNull function to determine whether an expression contains a Null value. In some cases, you want the expression to be value True, such as Ifvar=null and Ifvar<>null, but they are usually always False. This is because any expression containing a null itself is null, so the expression evaluates to False.
Instance 1
The code is as follows |
Copy Code |
Dim x document.write (IsNull (x) & "<br/>") x=10 document.write (IsNull (x) & "<br/>") x=empty document.write (IsNull (x) & "<br/>") x=null document.write (IsNull (x)) Output: False False False True |
The following example uses the IsNull function to determine whether a variable contains Null:
code is as follows |
copy code |
Dim MyVar, MyCheck MyCheck = IsNull (MyVar) ' return False MyVar = null & nbsp; ' is assigned null MyCheck = IsNull (MyVar) ' returns True MyVar = empty ' assigned to Empty MyCheck = IsNull (MyVar) ' return False IsEmpty () |
If the variable is uninitialized or explicitly set to Empty, the function isempty returns True; otherwise, the function returns FALSE. If ExPRession contains more than one variable, the total returns FALSE.
The following example uses the IsEmpty function to determine whether a variable can be initialized:
The code is as follows |
Copy Code |
Dim MyVar, MyCheck MyCheck = IsEmpty (MyVar) ' returns TRUE. MyVar = NULL ' is assigned null. MyCheck = IsEmpty (MyVar) ' returns FALSE. MyVar = Empty ' Fu to Empty. MyCheck = IsEmpty (MyVar) ' returns TRUE. |
3. 0 length string ("")
A 0-length string often refers to an empty string.
Str= "", assigning an empty string to a str variable, has been assigned, and is assigned a character
The difference between the three is:
IsNull is a type test that tests whether a null value (NULL) type.
IsEmpty is a value test that tests whether it is a null value. But the methods used in this different language are different.
= "" is a string test that tests whether the value is a null value.
Say a isempty, in some languages isempty is a null-value test that can test the following:
The code is as follows |
Copy Code |
Dim str As String IsEmpty (str) =true str = "" IsEmpty (str) =true str = NULL IsEmpty (str) =true Dim str As Integer str = 0 IsEmpty (str) = True |
That is, part of the language of the data in the 0, the character of the empty string, null values are used as null value of the test category.
But in C # and other languages, the requirements are more stringent, VB requirements are not very strict. As long as you know a special type of NULL type, its class is certainly null. There is also an undefined type in some languages:
Undefined type, as in C #:
String str;
Then string only has this one defined, so its value is not really defined at this time, it is the undefined type. This type often exists in C family language and Class C family such as ECMAScript family (JavaScript, etc.) and Java!
Add: In the database design you can specify that a field is null so that if it is no longer assigned to him, the record is null, but when the table is exported, the null record destroys the table's structure, that is, the grid lines in the table disappear, and many people may A default value is set in the database or an empty string is assigned to the record when processing.