vba 如何在 MS Access 中使 InStr 区分大小写
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11566342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I make InStr case sensitve in MS Access
提问by BIBD
How do I make InStr case sensitive in MS Access?
如何在 MS Access 中使 InStr 区分大小写?
I'd like the following to display 0
我想显示以下内容 0
msgbox InStr("In Here", "here")
Instead I get 4
.
相反,我得到4
.
I've tried adding vbBinaryCompare
我试过添加 vbBinaryCompare
msgbox InStr("In Here", "here", vbBinaryCompare)
but it complains about a type mismatch.
但它抱怨类型不匹配。
回答by BIBD
Use InStrB
instead of InStr
. Then it will do a byte by byte comparison instead of case insensitive.
使用InStrB
代替InStr
。然后它将逐字节比较而不是不区分大小写。
msgbox InStrB("In Here", "here")
Displays 0
.
显示0
。
回答by HansUp
The help topic doesn't make this point clear, but when you use the optional compareargument, you need to also supply the optional startargument in order to avoid that type mismatch complaint.
帮助主题没有明确说明这一点,但是当您使用可选的compare参数时,您还需要提供可选的start参数以避免出现类型不匹配的投诉。
So this displays 0 in the MsgBox
:
所以这在 0 中显示MsgBox
:
MsgBox InStr(1,"In Here", "here", vbBinaryCompare)