4个回答
2014-08-25
展开全部
以下为当在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
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
追问
谢谢您的回答。如果我还想同时检查是否只有一个m,应该怎么写呢,谢谢
追答
Dim i As Integer
i = InStr(Text1.Text, "m")'m在字符串中的位置,
If InStr(i + 1, Text1.Text, "m") > 0 Then'从i+1开始判断
MsgBox "还有m"
Else
MsgBox "没有了"
End If
展开全部
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
希望能解决您的问题。
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
希望能解决您的问题。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
正则表达式,字符处理必备
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim c As String, 是否含有字母M或m As Boolean
c = "abcdeMfgm"
是否含有字母M或m = (InStr(c, "M") > 0 Or InStr(c, "m") > 0)
MsgBox 是否含有字母M或m
c = "abcdeMfgm"
是否含有字母M或m = (InStr(c, "M") > 0 Or InStr(c, "m") > 0)
MsgBox 是否含有字母M或m
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询