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

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

VB.Net string contains exact match

vb.nettextbox

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

回答by Jaztingo

try to checkout this oneor this one

尝试结帐 这个这个

may be this one will help you :)

可能这个会帮助你:)