vb.net 在TextBox1中输入数字和空格,并求奇数数字,并求和
在TextBox1中输入数字和空格,输入其他字符自动清楚按Button1将其中奇数在TextBox2显示,分行显示或一行显示都行,将奇数数值之和在TextBox3显示最好...
在TextBox1中输入数字和空格,输入其他字符自动清楚
按Button1将其中奇数在TextBox2显示,分行显示或一行显示都行,将奇数数值之和在TextBox3显示
最好用正则表达式,否则太麻烦了 展开
按Button1将其中奇数在TextBox2显示,分行显示或一行显示都行,将奇数数值之和在TextBox3显示
最好用正则表达式,否则太麻烦了 展开
3个回答
展开全部
给你个参考的例子
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim a_point As Integer = TextBox1.SelectionStart
Dim bs As String = Regex.Replace(TextBox1.Text, "[^ \d]", "")
If TextBox1.TextLength > bs.Length Then
TextBox1.Text = bs
TextBox1.SelectionStart = a_point
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim gs() As String = (From mt As Match In Regex.Matches(TextBox1.Text, "\d*[13579]\b") Select mt.Value).ToArray
TextBox2.Lines = gs
TextBox3.Text = ((From mt As String In gs Select CInt(mt)).ToArray).Sum
End Sub
End Class
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim a_point As Integer = TextBox1.SelectionStart
Dim bs As String = Regex.Replace(TextBox1.Text, "[^ \d]", "")
If TextBox1.TextLength > bs.Length Then
TextBox1.Text = bs
TextBox1.SelectionStart = a_point
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim gs() As String = (From mt As Match In Regex.Matches(TextBox1.Text, "\d*[13579]\b") Select mt.Value).ToArray
TextBox2.Lines = gs
TextBox3.Text = ((From mt As String In gs Select CInt(mt)).ToArray).Sum
End Sub
End Class
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询