StrComp

本文介绍了StrComp函数的使用方法及参数设置,该函数用于比较两个字符串,并返回比较结果。StrComp支持二进制和文本两种比较方式,通过设置compare参数为0或1来指定比较类型。文中还提供了示例代码,展示了不同比较方式下的结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        StrComp 为字符串比较的函数,不是标准数据类型的比较函数,==是标准数据类型的比较符,如果用==来比较字符串,相当于比较2字符串(数组)的首地址。compare参数为0或者省略时按二进制按顺序从第一个字符开始作比较字符串的ASCII值的大小,compare参数为1时按文本比较字符串大小且此时不区分大小写。

StrComp Function

Returns a value indicating the result of a string comparison.

StrComp(string1, string2[, compare])
Arguments
string1
Required. Any valid string expression.
string2
Required. Any valid string expression.
compare
Optional. Numeric value indicating the kind of comparison to use when evaluating strings. If omitted, a binary comparison is performed. See Settings section for values.
Settings

The compare argument can have the following values:

ConstantValueDescription
vbBinaryCompare0Perform a binary comparison.
vbTextCompare1Perform a textual comparison.
Return Values

The StrComp function has the following return values:

IfStrComp returns
string1 is less than string2-1
string1 is equal to string20
string1 is greater than string21
string1 or string2 is NullNull
Remarks

The following example uses the StrComp function to return the results of a string comparison. If the third argument is 1, a textual comparison is performed; if the third argument is 0 or omitted, a binary comparison is performed.

Dim MyStr1, MyStr2, MyComp
MyStr1 = "ABCD": MyStr2 = "abcd"   ' Define variables.
MyComp = StrComp(MyStr1, MyStr2, 1)   ' Returns 0.
MyComp = StrComp(MyStr1, MyStr2, 0)   ' Returns -1.
MyComp = StrComp(MyStr2, MyStr1)   ' Returns 1.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值