VB.Net 字符串包含完全匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18437528/
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
VB.Net string contains exact match
提问by user2403705
I'm wondering if there is a way to search for an exact text match in a text box
我想知道是否有办法在文本框中搜索完全匹配的文本
for example
例如
using "if textbox1.text.contains("Hello") then" works
使用 "if textbox1.text.contains("Hello") then" 有效
however i only want it to search for text "Hello" and if i have 2 words like this
但是我只希望它搜索文本“你好”,如果我有两个这样的词
HelloFriend Hello Friend
你好朋友你好朋友
I only want it to find the word matching so the second statement Hello Friend and not HelloFriend as this doesn't match the keyword.
我只希望它找到匹配的单词,所以第二个语句 Hello Friend 而不是 HelloFriend 因为这与关键字不匹配。
Is this possible?
这可能吗?
回答by Guffa
You can make a regular expression that matches the word with word boundaries:
您可以制作一个与单词边界匹配的正则表达式:
if Regex.IsMatch(textbox1.Text, "\b" + Regex.Escape("Hello") + "\b") Then

