[英]VB.NET Find certain text in textbox
I have TextBox1
and TextBox2
我有TextBox1
和TextBox2
TextBox1
has this in it TextBox1
有这个
pooy
TextBox2
has this in it TextBox2
有这个
dalton austin chicken pooy boddy chicken
And when you click on Button1
it will look for the text "pooy" if it has it, it will go to Form2
if it doesn't nothing happens. 当你单击Button1
它会查找文本“pooy”,如果有的话,如果没有任何反应,它将转到Form2
。
How can I do this? 我怎样才能做到这一点?
EDIT: GOT IT WORKING 编辑:GOT IT WORKING
If TextBox1.Text.Contains(TextBox2.Text) Then
MsgBox("Activiated")
My.Settings.key = TextBox1.Text
Else
MsgBox("Invalid Key... ")
End If
It helps you to validate the text values only with string values 它可以帮助您仅使用字符串值验证文本值
if (!Regex.IsMatch(textBox3.Text, @"[a-zA-Z]"))
{
errorProvider2.SetError(textBox3, "Only use alphabets")
}
You can use either the .contains or .indexof methods. 您可以使用.contains或.indexof方法。 I believe in your example code you have it backards - it should be this, shouldn't it? 我相信你的示例代码你有它的支持 - 它应该是这个,不应该吗?
TextBox2.Text.Contains(TextBox1.Text)
As a side note, Contains is actually just a wrapper method for IndexOf that returns a Boolean. 作为旁注,Contains实际上只是IndexOf的一个返回布尔值的包装器方法。 (IndexOf will return -1 if the string is not found). (如果找不到字符串,IndexOf将返回-1)。
Inside Contains: 内部包含:
Public Function Contains(ByVal value As String) As Boolean
Return (Me.IndexOf(value, StringComparison.Ordinal) >= 0)
End Function
IndexOf is slightly more flexible since you change the case-sensitive option: 由于更改区分大小写的选项,IndexOf稍微灵活一些:
If myString.IndexOf(mySubstring, StringComparison.OrdinalIgnoreCase)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.