如何获取字符串中的前一个字符

时间:2013-08-08 17:07:59

标签: .net vb.net string visual-studio char

我正在创建一个函数,允许我在for循环期间获取字符串中的前一个字符。

Private Sub TSButton_Click(sender As Object, e As EventArgs) Handles TSButton.Click
    For Each ch As Char In HTextDisplay.Text
        MsgBox("the previous characters here")
        'carry out function here
    Next
End Sub

所以,如果HTextDisplay.Text是“ABCDEFG”,那么msgbox将显示“A”,然后是“B”,然后是“C”......

另一方面,如果我可以检查for循环函数中是否有字符后面的字符,我可能会更好

1 个答案:

答案 0 :(得分:0)

dim previousChar as char = ""
For Each ch as Char in HTextDisplay.Text
    msgbox ch & " - previous character = " & previousChar
    'other processing
    previouschar = ch
Next