首页 > 解决方案 > Like 运算符无法检测到字符串中的字符

问题描述

目前,我的代码无法正确检测字符串是否具有特定字符。

为了简单的解释。请参考这个:

Dim strSample as String = "Y1-K99"

如果字符串会检测到是否strSample有字母K ,我尝试了这段代码。

If (strSample  Like "##K*" Or strSample Like "###K*") Then
'Do Something
End if

If Else condition但即使它有一个 K ,它也不会触发或转到内部函数。

标签: stringvb.net

解决方案


如果您在 "strSample has a letter K" 之后,则需要将 IF 条件更改为

If (strSample  Like "*K*") Then
'Do Something
End if

阅读此 Like 运算符


推荐阅读