在文本框中粘贴后,希望能像123.123.123.2 显示,每三位打个点。下面代码 i += 1执行不到,为什么?
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim i As Integer
For i = 0 To TextBox1.Text.Length
If i Mod 4 = 0 Then
TextBox1.Text = TextBox1.Text.Insert(i, ". ")
i += 1
End If
Next
End Sub
[解决办法]
TextBox1.Text = TextBox1.Text.Insert(i, ". ") 因为这一句会引发新的 TextBox1_TextChanged 事件,so...
[解决办法]
dim d as double=1231231234
dim strv as string=reserve(d.tostring())
dim strtemp as string=string.format(val(strv ), "###,000 ").replace( ", ", ". ")
msgbox(reserve(strtemp ))
-------在网吧里,不能测试,大致意思就是这样的,先反转4321321321-》4,321,321,321-》
4.321.321.321-》123.123.123.4
[解决办法]
用正则表达式最简单
Regex.IsMatch(TextBox1.Text, "^((1??\d{1,2}|2[0-4]\d|25[0-5])\.){3}(1??\d{1,2}|2[0-4]\d|25[0-5])$ ")
[解决办法]
Private Sub TextBox5_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox5.LostFocus
Dim i As Integer
Dim length As Integer
length = TextBox5.Text.Trim.Length + TextBox5.Text.Trim.Length \ 3
For i = 0 To length
If i Mod 4 = 0 Then
TextBox5.Text = TextBox5.Text.Insert(i, ". ")
i += 1
End If
Next
TextBox5.Text = TextBox5.Text.Substring(1)
End Sub
根据楼主写的改了下,刚测了下应该对的
[解决办法]
直接使用MaskTextBox控件就可以了。