What is the '<>' asp operator?

2019-01-27 12:24发布

问题:

Simple question. I tried searching, by googling for less than and greater than signs doesn't return great results.

My guess is that <> is basically equivalent to not equals. So, the below expression would be false if x is null or an empty string, and true otherwise?

if x <> ""

回答1:

So, the below expression would be false if x is null or an empty string, and true otherwise?

Not exactly. There are few function to verify value:

IsNull(expression)

IsNull returns True if expression is Null, that is, it contains no valid data; otherwise, IsNull returns False. If expression consists of more than one variable, Null in any constituent variable causes True to be returned for the entire expression.

The Null value indicates that the variable contains no valid data. Null is not the same as Empty, which indicates that a variable has not yet been initialized. It is also not the same as a zero-length string (""), which is sometimes referred to as a null string.

IsEmpty(expression)

The expression argument can be any expression. However, because IsEmpty is used to determine if individual variables are initialized, the expression argument is most often a single variable name.

IsEmpty returns True if the variable is uninitialized, or is explicitly set to Empty; otherwise, it returns False. False is always returned if expression contains more than one variable.

Other good function

VarType(varname)

Returns a value indicating the subtype of a variable.

Use Windows Script 5.6 Documentation from http://www.microsoft.com/en-us/download/details.aspx?id=2764



回答2:

This would also return True if a value is contained in the entity listed. This is commonly used to look for quesrystring or form elements that may or may not have been supplied:

If Request("someFieldName") <> "" Then
  ' Field was provided and has a value, so use the field value
Else
  ' Field was either empty or not provided, in which case use something else
End If

Hope this helps.



标签: asp-classic