回答編集履歴
2
追記
test
CHANGED
@@ -63,3 +63,47 @@
|
|
63
63
|
}
|
64
64
|
|
65
65
|
```
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
--- iniについて
|
70
|
+
|
71
|
+
ライブラリつかってパースはもしかしたら今はつらいのかもしれないので、ご提示の要件からするともう単純にテキスト比較すればいいんじゃないと思い、こういうコードを書いてみました。
|
72
|
+
|
73
|
+
```csharp
|
74
|
+
|
75
|
+
using System;
|
76
|
+
|
77
|
+
using System.Text;
|
78
|
+
|
79
|
+
using System.IO;
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
namespace CsvParser
|
84
|
+
|
85
|
+
{
|
86
|
+
|
87
|
+
class Program
|
88
|
+
|
89
|
+
{
|
90
|
+
|
91
|
+
static void Main(string[] args)
|
92
|
+
|
93
|
+
{
|
94
|
+
|
95
|
+
var txt = File.ReadAllText(@"C:\work\test.ini", Encoding.GetEncoding("shift_jis"));
|
96
|
+
|
97
|
+
if(txt.Contains("S/N_LEN=11")) { return; }
|
98
|
+
|
99
|
+
if(txt.Contains("ShutDown=OFF")) { return; }
|
100
|
+
|
101
|
+
//ここから処理を継続すれば、↑のパターンを除外できます
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
```
|
1
改訂
test
CHANGED
@@ -1,33 +1,65 @@
|
|
1
|
-
|
1
|
+
[ここ](https://webbibouroku.com/Blog/Article/textfieldparser-csv)を参考にしたのでしょうか。
|
2
2
|
|
3
|
-
|
3
|
+
年齢が25歳の行のときだけOKとするようにかいてみました。
|
4
|
-
|
5
|
-
{
|
6
|
-
|
7
|
-
Console.Write(field + "\t");
|
8
|
-
|
9
|
-
}
|
10
|
-
|
11
|
-
```
|
12
|
-
|
13
|
-
ここのところで、
|
14
4
|
|
15
5
|
```csharp
|
16
6
|
|
17
|
-
|
7
|
+
using System;
|
18
8
|
|
19
|
-
|
9
|
+
using System.Linq;
|
20
10
|
|
21
|
-
|
11
|
+
using System.Text;
|
22
12
|
|
23
|
-
|
13
|
+
using Microsoft.VisualBasic.FileIO;
|
24
14
|
|
25
|
-
Console.Write("OK");
|
26
15
|
|
27
|
-
}
|
28
16
|
|
17
|
+
namespace CsvParser
|
18
|
+
|
19
|
+
{
|
20
|
+
|
21
|
+
class Program
|
22
|
+
|
23
|
+
{
|
24
|
+
|
25
|
+
static void Main(string[] args)
|
26
|
+
|
27
|
+
{
|
28
|
+
|
29
|
+
var parser = new TextFieldParser(@"C:\work\test.csv", Encoding.GetEncoding("Shift_JIS"))
|
30
|
+
|
31
|
+
{ TextFieldType = FieldType.Delimited, HasFieldsEnclosedInQuotes = true, TrimWhiteSpace = false, Delimiters = new[] { "," } };
|
32
|
+
|
33
|
+
using (parser)
|
34
|
+
|
35
|
+
{
|
36
|
+
|
37
|
+
var header = parser.ReadFields().Select((field, index)=>new { field, index}).ToDictionary(a => a.field, a => a.index);
|
38
|
+
|
39
|
+
// ファイルの終端までループ
|
40
|
+
|
41
|
+
while (!parser.EndOfData)
|
42
|
+
|
43
|
+
{
|
44
|
+
|
45
|
+
// フィールドを読込
|
46
|
+
|
47
|
+
string[] row = parser.ReadFields();
|
48
|
+
|
49
|
+
if(row[header["年齢"]] == "25") { Console.Write("OK"); }
|
50
|
+
|
51
|
+
Console.WriteLine("←");
|
52
|
+
|
29
|
-
|
53
|
+
}
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
Console.ReadKey();
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
}
|
30
64
|
|
31
65
|
```
|
32
|
-
|
33
|
-
ということでしょうか
|