wildcard character using like operator vb.net

家住魔仙堡 提交于 2020-01-05 12:33:51

问题


I have a problem using "like" operator.

I want to find strings, in a table, like "Address #123" or "Address #56778" or "Address #2b". So, I wrote this in my code:

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?


回答1:


You can escape the special characters [ ? # * by enclosing them in square brackets [ ]. For more information see the Like Operator reference.

If m_Table.Rows(i).Item("NOTE").ToString Like "*ADDRESS [#]*" Then

Another option is to use StartsWith, EndsWith or Contains methods of the string class instead.

If m_Table.Rows(i).Item("NOTE").ToString().Contains("ADDRESS #") Then


来源:https://stackoverflow.com/questions/25041006/wildcard-character-using-like-operator-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!