Advertisement
Guest User

SomeDich

a guest
Dec 2nd, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. string s = "";
  4. while (s != "hare")
  5. {
  6. Console.Write("Input:");
  7. s = Console.ReadLine();
  8. long p = Convert.ToInt64(s);
  9. s = SizeFormat(p);
  10. Console.WriteLine(s);
  11. Console.ReadLine();
  12. }
  13. }
  14.  
  15. static string SizeFormat(long size)
  16. {
  17. string sizeStr = size.ToString();
  18. string result = "";
  19.  
  20. do
  21. {
  22. if (sizeStr.Length >= 3)
  23. {
  24. result = sizeStr.Substring(sizeStr.Length - 3) + " " + result;
  25. sizeStr = sizeStr.Remove(sizeStr.Length - 3);
  26. }
  27. else
  28. {
  29. result = sizeStr.Substring(sizeStr.Length - 1) + " " + result;
  30. sizeStr = sizeStr.Remove(sizeStr.Length - 1);
  31. }
  32.  
  33. }
  34. while (sizeStr != "");
  35.  
  36. if (result.StartsWith(" "))
  37. {
  38. result = result.Substring(1);
  39. }
  40. if (result.EndsWith(" "))
  41. {
  42. result = result.Substring(0, result.Length - 1);
  43. }
  44.  
  45. return result;
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement