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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 16:57:47  来源:igfitidea点击:

How do I make InStr case sensitve in MS Access

stringms-accessvbastring-comparison

提问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 InStrBinstead 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)