如果后跟任何字符visual basic,请替换string

时间:2016-04-02 12:23:17

标签: vb.net logic sql-like

我是Visual Basic的新手。我想在like中使用textbox运算符来更改字符,如果后跟任何其他字符。但它应该在key-up事件上。

任何人都可以帮助我:我如何使以下代码有效?

Public Class Form1
Dim myString As String
Dim sMatch As Boolean = myString Like "x?"

Private Sub TextBox1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
    If sMatch = True Then
        TextBox1.Text = TextBox1.Text.Replace(myString, "z")
    End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    myString = "x"
End Sub
End Class

1 个答案:

答案 0 :(得分:0)

试试这个然后问。您的变量myString从未从TextBox中获取它的值。您只需在x事件中将其设置为load

Public Class Form1
Private Sub TextBox1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
    If TextBox1.Text Like "x?" Then
        TextBox1.Text = TextBox1.Text.Replace(TextBox1.Text, "z")
    End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    TextBox1.Text = "x"
End Sub
End Class