Created
July 19, 2012 16:36
-
-
Save CalvinRodo/3145160 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Original | |
Public Shared Function FormatClientNumber(num As String) As String | |
Dim count As Integer = num.Length \ 3 | |
If num.Length Mod 3 = 0 Then count -= 1 'no trailing dash | |
'If count > 3 Then count = 3 'format is ABC-999-999-123456789.. | |
For i As Integer = count To 1 Step -1 | |
num = num.Insert(i * 3, "-") | |
Next | |
Return num | |
End Function | |
'Change to this | |
Public Shared Function FormatClientNumber(num As String) As String | |
Dim count As Integer = num.Length \ 3 | |
'Emphasize the order of the operations | |
If (num.Length Mod 3) = 0 Then | |
return num 'no trailing dash, no need to go through for loop | |
End If | |
'If count > 3 Then count = 3 'format is ABC-999-999-123456789.. | |
For i As Integer = count To 1 Step -1 | |
num = num.Insert(i * 3, "-") | |
Next | |
Return num | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment