' Here is the basic algorithm you need, when you are done testing simply change "xxx-xxx-xx" into " - - " Dim AccountCode As String = "12345" Dim triplets As Int16 = CShort(Math.Floor((AccountCode.Length - 1) / 3)) Dim AccountCodeFormatted As String = Format(Val(AccountCode), "###-###-##".Substring(0, AccountCode.Length + triplets)) _ + "xxx-xxx-xx".Substring(AccountCode.Length + triplets) ' And here is some test code that will write to the Output window. System.Diagnostics.Debug.WriteLine(smartFormat("1")) System.Diagnostics.Debug.WriteLine(smartFormat("12")) System.Diagnostics.Debug.WriteLine(smartFormat("123")) System.Diagnostics.Debug.WriteLine(smartFormat("1234")) System.Diagnostics.Debug.WriteLine(smartFormat("12345")) System.Diagnostics.Debug.WriteLine(smartFormat("123456")) System.Diagnostics.Debug.WriteLine(smartFormat("1234567")) System.Diagnostics.Debug.WriteLine(smartFormat("12345678")) Public Function smartFormat(ByVal AccountCode As String) As String Dim lengthPlusHyphens As Int32 = AccountCode.Length _ + CInt(Math.Floor((AccountCode.Length - 1) / 3)) Return Format(Val(AccountCode), "###-###-##".Substring(0, lengthPlusHyphens)) _ + "xxx-xxx-xx".Substring(lengthPlusHyphens) End Function