Advertisement
perjespersson

Real indata

Nov 5th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9.  
  10. int HowManyDecimal(string input)
  11. {
  12. input = input.Substring(input.IndexOf('.') + 1);
  13. if (input.Contains("E"))
  14. {
  15. input = input.Remove(input.IndexOf('E'));
  16. }
  17.  
  18. return input.Length;
  19. }
  20.  
  21. bool IsDate(ref string input)
  22. {
  23. return input.Contains("-") && !input.Contains("E");
  24. }
  25.  
  26. bool IsTime(ref string input)
  27. {
  28. return input.Contains(":");
  29. }
  30.  
  31. bool IsMeasure(ref string input)
  32. {
  33. return HowManyDecimal(input) == 2;
  34. }
  35.  
  36. bool IsLocation(ref string input)
  37. {
  38. return HowManyDecimal(input) == 3;
  39. }
  40.  
  41. bool IsResult(ref string input)
  42. {
  43. return input[0] == 'A' || input[0] == 'R';
  44. }
  45.  
  46. string Date ="";
  47. string Time = "";
  48. string Measure = "";
  49. string Location = "";
  50. string Result = "";
  51.  
  52. string Input2 = "2019-10-29\t17:45:21\t3.44E-6\t5.454\tReject\r\n";
  53. string Input3 = "2019-10-29\t17:45:21\t0.00\t5.454\tReject\r\n";
  54. string Input = "2019-10-29\t3.44E-6\t5.454\tReject\r\n";
  55. string Input5 = "17:45:21\t3.44E-6\t5.454\tReject\r\n";
  56. string Input4 = "17:45:21\t5.454\tReject\r\n";
  57. string Input6 = "5.454\tReject\r\n";
  58.  
  59. string[] strlist = Input.Split("\t");
  60.  
  61. for(int i = 0; i < strlist.Length; i++)
  62. {
  63. if (IsDate(ref strlist[i]))
  64. Date = strlist[i];
  65.  
  66. else if(IsTime(ref strlist[i]))
  67. Time = strlist[i];
  68.  
  69. else if (IsMeasure(ref strlist[i]))
  70. Measure = strlist[i];
  71.  
  72. else if (IsLocation(ref strlist[i]))
  73. Location = strlist[i];
  74.  
  75. else if (IsResult(ref strlist[i]))
  76. Result = strlist[i];
  77. }
  78.  
  79. Console.WriteLine("Date: " + Date + "\n" + "Time: " + Time + "\n" + "Measure: " + Measure + "\n" + "Location: " + Location + "\n" + "Result: " + Result + "\n");
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement