How to format string into phone number C#
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | class Program { static void Main(string[] args) { //this line create a double variable for hold telephone number. double phoneNumber = 1112223333; Console.WriteLine("formatted string.............."); Console.WriteLine("Double value: " + phoneNumber); Console.WriteLine("Format phone number: " + phoneNumber.ToString("###-###-####")); Console.WriteLine("\nAnother option: " + string.Format("{0:###-###-####}", phoneNumber)); Console.WriteLine("Another option: " + string.Format("{0:(###) ###-####}", phoneNumber)); Console.ReadLine(); } } |
Output:
1 2 3 4 5 6 7 8 | formatted string.............. Double value: 1112223333 Format phone number: 111-222-3333 Another option: 111-222-3333 Another option: (111) 222-3333 |
Phone Number C# United States