Greg Koc Greg Koc - 1 month ago 16
Vb.net Question

check a specific character in textbox visual basic?

Lets say i have a textbox containing the string "hello".

Is there a way in which can i check that the 3rd character of textbox.text = "l"?

We are talking about visual basic, of course.

Thanks!

Answer

You could use this function

Private Function checkCharacter(thisString As String,
                                searchCharacter As Char,
                                index As Integer)
    Try
        Return thisString(index) = searchCharacter
    Catch
        Return False
    End Try
End Function

Call it like this

Dim result As Boolean = checkCharacter(TextBox1.Text, "l"c, 2)