kyrathasoft

tdi

Jul 21st, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.86 KB | None | 0 0
  1. using System;
  2. using TestInput;
  3. /*
  4. from Lesson 6 of C# console programming tutorial series at following URL:
  5. http://williammillerservices.com/windows-c-console-programming/
  6.  
  7. demonstrates use helper methods to parse strings to (a) DateTime and (b) integer
  8. GitHub gist -> https://gist.github.com/kyrathasoft/962953a66777ad52325f06d91140d525
  9. Pastebin.com -> https://pastebin.com/u5Rc2XRe
  10. */
  11. namespace TestParsingOfStringToDateAndToInteger
  12. {
  13.     class MyTesterClass
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             //two test strings
  18.             string sTest1 = "the ninth of July, 2018";
  19.             string sTest2 = "7/9/2018";
  20.  
  21.             //and another two...
  22.             string sTest3 = "four";
  23.             string sTest4 = "4";
  24.  
  25.             Console.WriteLine(); //print blank line...
  26.  
  27.             CanParseToDate(sTest1);
  28.             CanParseToDate(sTest2);
  29.  
  30.             CanParseToInt(sTest3);
  31.             CanParseToInt(sTest4);
  32.         }
  33.  
  34.         static void CanParseToDate(string p)
  35.         {
  36.             if (Tester.IsDate(p))
  37.             {
  38.                 /* We use a placeholder for variable 'p' value and we end
  39.                 the argument passed to WriteLine() with an extra line: \n
  40.                 to aid readability during program execution */
  41.                 Console.WriteLine("\"{0}\" can be parsed to a DateTime.\n", p);
  42.             }
  43.             else
  44.             {
  45.                 Console.WriteLine("\"{0}\" cannot be parsed to a DateTime.\n", p);
  46.             }
  47.         }
  48.  
  49.         static void CanParseToInt(string p)
  50.         {
  51.             if (Tester.IsInteger(p))
  52.             {
  53.                 Console.WriteLine("\"{0}\" can be parsed to an integer.\n", p);
  54.             }
  55.             else
  56.             {
  57.                 Console.WriteLine("\"{0}\" cannot be parsed to an integer.\n", p);
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment