使用 like 运算符 vb.net 的通配符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25041006/
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
wildcard character using like operator vb.net
提问by djobert
I have a problem using "like" operator.
我在使用“like”运算符时遇到问题。
I want to find strings, in a table, like "Address #123" or "Address #56778" or "Address #2b". So, I wrote this in my code:
我想在表格中查找字符串,例如“地址 #123”或“地址 #56778”或“地址 #2b”。所以,我在我的代码中写了这个:
If m_Table.Rows(i).Item("NOTE").ToString Like "*ADDRESS #*" Then
But, the code reads the "#" as a wildcard, not a simple character.
但是,代码将“#”读取为通配符,而不是简单的字符。
How can I rewrite my code to make it read the # as a simple character, not a wildcard?
如何重写我的代码以使其将 # 作为简单字符而不是通配符读取?
回答by Bj?rn-Roger Kringsj?
You can escape the special characters [ ? # *by enclosing them in square brackets [ ]. For more information see the Like Operatorreference.
您可以转义特殊字符[ ? #*将它们括在方括号[] 中。有关更多信息,请参阅Like Operator参考。
If m_Table.Rows(i).Item("NOTE").ToString Like "*ADDRESS [#]*" Then
Another option is to use StartsWith, EndsWithor Containsmethods of the string class instead.
另一种选择是使用字符串类的StartsWith、EndsWith或Contains方法。
If m_Table.Rows(i).Item("NOTE").ToString().Contains("ADDRESS #") Then

