如何在vb中检查文本框中包含特定字符

求帮助,想检查文本框里是否含有某些字母比如M和m,谢谢
2024-11-24 09:26:24
推荐回答(4个)
回答1:

以下为当在text1中按下按键时,判断是否为m或M,如果是,则帆肢屏蔽输入
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = "m" Or Chr(KeyAscii) = "M" Then
KeyAscii = 0
End If
End Sub
以下为判断文本框是否包含字符

Private Sub Command1_Click()
If InStr(LCase(Text1.Text), "m") > 0 Then '当包态迹世含m或M时
'包含
Else
'不州蚂包含
End If
End Sub

回答2:

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
abc(TextBox1.Text)
End Sub
Private Function abc(ByVal s As String) As Boolean
If s.Length = 0 Or InStr(s, " ") = 0 Then abc = False : Exit Function
Dim r As String = ""
If s.Substring(0, 1) = "/" Then r = s.Substring(1, InStr(s, " ") - 2)
Dim t As String = IO.File.ReadAllText("地消袜判址", System.Text.Encoding.Default)
Return CBool(InStr(t, r))
End Function
希望能解决您的好乎问拿改题。

回答3:

正则表达式,字符处理必备

回答4:

Dim c As String, 是否含有字母M或m As Boolean
c = "abcdeMfgm"清郑
是否含有字母M或m = (InStr(c, "M") > 0 Or InStr(c, "斗乎m") > 0)
MsgBox 是空正悉否含有字母M或m