Advertisement
hackthecode

Input Phone Number Formatting 2

Nov 16th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. using System;
  2.  
  3. class Tel
  4. {
  5.     public static void Main()
  6.     {
  7.         string tel = "(+359) ";
  8.         Console.Write("{0}", tel);
  9.         ConsoleKeyInfo key;
  10.  
  11.         int count = 0;
  12.  
  13.         do
  14.         {
  15.             key = Console.ReadKey();
  16.             tel += key.KeyChar;
  17.             count++;
  18.  
  19.             int x = tel.Length;
  20.            
  21.             if (count > 2 && count % 2 == 1)
  22.             {
  23.                 Console.SetCursorPosition(x + 1, 0);
  24.                 tel += " ";
  25.             }
  26.  
  27.         } while (key.Key != ConsoleKey.Enter && count < 9);
  28.  
  29.         Console.WriteLine();
  30.         Console.WriteLine(tel);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement