📜  VBScript-运算符

📅  最后修改于: 2020-10-19 04:06:18             🧑  作者: Mango


什么是运算符?

让我们接受一个表达式4 + 5等于9 。在这里,4和5称为操作数,而+称为运算符。 VBScript语言支持以下类型的运算符-

  • 算术运算符
  • 比较运算符
  • 逻辑(或关系)运算符
  • 串联运算符

算术运算符

VBScript支持以下算术运算运算符-

假设变量A持有5,变量B持有10,则-

显示范例

Operator Description Example
+ Adds two operands A + B will give 15
Subtracts second operand from the first A – B will give -5
* Multiply both operands A * B will give 50
/ Divide numerator by denumerator B / A will give 2
% Modulus Operator and remainder of after an integer division B MOD A will give 0
^ Exponentiation Operator B ^ A will give 100000

要更好地了解这些运算符,可以自己尝试

比较运算符

有下列通过的VBScript语言支持的比较运算符-

假设变量A持有10,变量B持有20,则-

显示范例

Operator Description Example
= Checks if the value of two operands are equal or not, if yes then condition becomes true. (A == B) is False.
<> Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (A <> B) is True.
> Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is False.
< Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B) is True.
>= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is False.
<= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is True.

要更好地了解这些运算符,可以自己尝试

逻辑运算符

VBScript语言支持以下逻辑运算符-

假设变量A持有10,变量B持有0,则-

显示范例

Operator Description Example
AND Called Logical AND operator. If both the conditions are True, then Expression becomes True. a<>0 AND b<>0 is False.
OR Called Logical OR Operator. If any of the two conditions is True, then condition becomes True. a<>0 OR b<>0 is true.
NOT Called Logical NOT Operator. It reverses the logical state of its operand. If a condition is True, then the Logical NOT operator will make it False. NOT(a<>0 OR b<>0) is false.
XOR Called Logical Exclusion. It is the combination of NOT and OR Operator. If one, and only one, of the expressions evaluates to True, result is True. (a<>0 XOR b<>0) is true.

要更好地了解这些运算符,可以自己尝试

串联运算符

VBScript语言支持以下串联运算符-

假设变量A持有5,变量B持有10,则-

显示范例

Operator Description Example
+ Adds two Values as Variable Values are Numeric A + B will give 15
& Concatenates two Values A & B will give 510

假设变量A =“ Microsoft”和变量B =“ VBScript”,然后-

Operator Description Example
+ Concatenates two Values A + B will give MicrosoftVBScript
& Concatenates two Values A & B will give MicrosoftVBScript

–串联运算符可用于数字和字符串。如果变量包含数字值或字符串值,则输出取决于上下文。

为了更好地了解这些操作员,您可以自己尝试