Public Class Form1
Public digits As String = "0123456789"
Public userInput As String
Public digitCount As Integer = 0
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
userInput = Console.ReadLine()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For Each i As Char In userInput
If digits.Contains(i) Then digitCount += 1
Next
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub MaskedTextBox1_MaskInputRejected(sender As Object, e As MaskInputRejectedEventArgs) Handles MaskedTextBox1.MaskInputRejected
End Sub
结束班
我的循环应该是什么,因为这个循环不起作用以及在我的maskedtextbox1中输入我的digitCount的语法是什么
答案 0 :(得分:0)
用以下简单语句替换你的循环:
digitCount = userInput.Count(Function(c) Char.IsDigit(c))
N.B。需要引用System.Linq,默认情况下是这样。