回答編集履歴
3
修正
test
CHANGED
@@ -40,7 +40,9 @@
|
|
40
40
|
|
41
41
|
|
42
42
|
|
43
|
-
もっと簡単にこうも書けます。
|
43
|
+
もっと簡単にこうも書けます。Encoding は省いて文字列対象にしました。
|
44
|
+
|
45
|
+
バイトデータから文字列を取り出すのは上記のように簡単なので。
|
44
46
|
|
45
47
|
|
46
48
|
|
2
追記
test
CHANGED
@@ -37,3 +37,21 @@
|
|
37
37
|
}
|
38
38
|
|
39
39
|
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
もっと簡単にこうも書けます。
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
```C#
|
48
|
+
|
49
|
+
static IEnumerable<string> SplitLines(string str)
|
50
|
+
|
51
|
+
{
|
52
|
+
|
53
|
+
return Regex.Split(str, "\r?\n");
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
```
|
1
追記
test
CHANGED
@@ -1 +1,39 @@
|
|
1
1
|
このコードに使いまわせる部分は無いと思います。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
###追記
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
使いまわすならこんな風に書きます。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
```C#
|
14
|
+
|
15
|
+
public static IEnumerable<string> SplitLines(byte[] buffer, Encoding encoding)
|
16
|
+
|
17
|
+
{
|
18
|
+
|
19
|
+
using (var reader = new StringReader(encoding.GetString(buffer)))
|
20
|
+
|
21
|
+
{
|
22
|
+
|
23
|
+
while (true)
|
24
|
+
|
25
|
+
{
|
26
|
+
|
27
|
+
string result = reader.ReadLine();
|
28
|
+
|
29
|
+
if (result == null) break;
|
30
|
+
|
31
|
+
yield return result;
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
```
|