Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using TestInput;
- /*
- from Lesson 6 of C# console programming tutorial series at following URL:
- http://williammillerservices.com/windows-c-console-programming/
- demonstrates use helper methods to parse strings to (a) DateTime and (b) integer
- GitHub gist -> https://gist.github.com/kyrathasoft/962953a66777ad52325f06d91140d525
- Pastebin.com -> https://pastebin.com/u5Rc2XRe
- */
- namespace TestParsingOfStringToDateAndToInteger
- {
- class MyTesterClass
- {
- static void Main(string[] args)
- {
- //two test strings
- string sTest1 = "the ninth of July, 2018";
- string sTest2 = "7/9/2018";
- //and another two...
- string sTest3 = "four";
- string sTest4 = "4";
- Console.WriteLine(); //print blank line...
- CanParseToDate(sTest1);
- CanParseToDate(sTest2);
- CanParseToInt(sTest3);
- CanParseToInt(sTest4);
- }
- static void CanParseToDate(string p)
- {
- if (Tester.IsDate(p))
- {
- /* We use a placeholder for variable 'p' value and we end
- the argument passed to WriteLine() with an extra line: \n
- to aid readability during program execution */
- Console.WriteLine("\"{0}\" can be parsed to a DateTime.\n", p);
- }
- else
- {
- Console.WriteLine("\"{0}\" cannot be parsed to a DateTime.\n", p);
- }
- }
- static void CanParseToInt(string p)
- {
- if (Tester.IsInteger(p))
- {
- Console.WriteLine("\"{0}\" can be parsed to an integer.\n", p);
- }
- else
- {
- Console.WriteLine("\"{0}\" cannot be parsed to an integer.\n", p);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment