i have a set of phone numbers loaded into my text-box and i want to format the record such that each phone number of 11 digits is separated by a comma. that is after every 11 digits a comma will be automatically placed. please what code do i use in VB.net
how do i format the text in my textbox
Collapse
X
-
Tags: None
-
-
Code:'Get the length of characters in the text box Dim textBoxLength As Integer = TextBox1.Text.Length 'Format the textbox character length by dividing by 11 (phone number length) and subtracting 1 (total number of commas to add) Dim textLength As Integer = textBoxLength / 11 - 1 'Make i an integer which is equal to the textLength variable. This is not necessary, just pretty Dim i As Integer = textLength 'Loop in reverse order, inserting a comma every 11th character 'We are looping backwards since the length of the textbox text changes with every insertion Do Until i = 0 TextBox1.Text = TextBox1.Text.Insert(11 * i, ",") i = i - 1 LoopComment
Comment