如何在vb.net的文本框中逐个读取字符

时间:2016-03-25 06:11:50

标签: vb.net string iteration substring character

我想在vb.net的文本框中读取用户给出的值。 如果他们给出值ABC,我想逐个读取字符串并在另一个文本框中显示特定字符​​(例如第3个字符(c))。

2 个答案:

答案 0 :(得分:3)

假设您有2个文本框和一个按钮:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim textBox1InputString As String
    textBox1InputString = TextBox1.Text

    ' Call ToCharArray function.
    Dim array() As Char = textBox1InputString.ToCharArray

    ' If we input ABC and we want C
    TextBox2.Text = array(2)

End Sub

答案 1 :(得分:1)

For i = 0 To TextBox1.Text.Length
    If i = 2 Then
        TextBox2.Text = TextBox1.Text(i)
    End If

Next