teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

f___

2018/11/07 03:08

投稿

papinianus
papinianus

スコア12705

answer CHANGED
@@ -11,8 +11,37 @@
11
11
  [TextItem],,,,,,,,,,,
12
12
  番号,測定項目名,コメント,測定コマンド,,,,,,,,,,,
13
13
  ,,,INIT,1,,,,,,,
14
- ,,,WATI_T,100,,,,,,,
14
+ ,,,WAIT_T,100,,,,,,,
15
15
  ,,,DISP,,,,,,,,
16
16
  ,,,MEAS,BLUR,2,48,1,,,,
17
17
 
18
+ ```
19
+
20
+ ```csharp
21
+ using System;
22
+ using System.Linq;
23
+ using System.Collections.Generic;
24
+ using System.Text;
25
+ using System.IO;
26
+
27
+ namespace CsvParser
28
+ {
29
+ class Program
30
+ {
31
+ static void Main(string[] args)
32
+ {
33
+ var txt = File.ReadLines(@"C:\work\Item.csv", Encoding.GetEncoding("shift_jis")).ToArray();
34
+ if (IsShutDownOff(txt)) { Console.WriteLine("中断(シャットダウンオフ)"); Console.ReadKey(); return; }
35
+ if (IsSerialNumberLength11(txt)) { Console.WriteLine("中断(S/N_LEN=11)"); Console.ReadKey(); return; }
36
+ var initVal = findNextOfKey(txt, "INIT");
37
+ var waitVal = findNextOfKey(txt, "WAIT_T");
38
+ Console.WriteLine($"INIT = {initVal} , WAIT_T = {waitVal}");
39
+ }
40
+ static bool IsShutDownOff(IEnumerable<string> lines) => lines.Any(line => line.Contains("Shutdown=OFF"));
41
+ static bool IsSerialNumberLength11(IEnumerable<string> lines) => lines.Any(line => line.Contains("S/N_LEN=11"));
42
+ static string firstLineWhichHas(IEnumerable<string> lines, string key) => lines.FirstOrDefault(line => line.Contains(key));
43
+ static string getNextOf(string line, string key) => line?.Split(',').SkipWhile(col => col.Trim().ToLower() != key.ToLower()).ElementAt(1).Trim() ?? string.Empty;
44
+ static string findNextOfKey(IEnumerable<string> lines, string key) => getNextOf(firstLineWhichHas(lines, key), key);
45
+ }
46
+ }
18
47
  ```