質問編集履歴

6

できていることを削りました。

2018/11/30 06:47

投稿

detti0101
detti0101

スコア13

test CHANGED
File without changes
test CHANGED
@@ -1,8 +1,8 @@
1
1
  #やりたいこと
2
2
 
3
- テキストファイルに書かれている文字列の先頭を
3
+ テキストファイルを読み込んでそこに書かれている
4
4
 
5
- 検知しそこに文字列を挿入したい
5
+ 文字列の先頭を検知しそこに文字列を挿入したい
6
6
 
7
7
  **※各行の先頭ではない**
8
8
 
@@ -34,74 +34,6 @@
34
34
 
35
35
 
36
36
 
37
- #できていること/最終目標
38
-
39
- テキストファイルを1行ずつ読み込んで表示しさらに
40
-
41
- 次の行に読み取り可能な文字列がある場合「A」を表示
42
-
43
-
44
-
45
- ```C#
46
-
47
- StreamReader text_file = new StreamReader(@"sample.txt", Encoding.GetEncoding("UTF-8"));
48
-
49
-   string file = null;
50
-
51
- while (text_file.Peek() != -1)
52
-
53
- {
54
-
55
- file = text_file.ReadLine();
56
-
57
- string matsubi = "";
58
-
59
- //次の行に読み取り可能な文字があるなら"A"を表示
60
-
61
- if (text_file.Peek() >= 0)
62
-
63
- {
64
-
65
- matsubi = "A";
66
-
67
- }
68
-
69
- file += matsubi;
70
-
71
- }
72
-
73
- Console.WriteLine(file);
74
-
75
- ```
76
-
77
- 上記コードの結果
78
-
79
- =============
80
-
81
- テキストが書かれています。A
82
-
83
- テキストが書かれています。A
84
-
85
- テキストが書かれています。
86
-
87
- =============
88
-
89
-
90
-
91
- ・最終的にしたいこと↓
92
-
93
- =============
94
-
95
- TESTテキストが書かれています。A
96
-
97
- テキストが書かれています。A
98
-
99
- テキストが書かれています。
100
-
101
- =============
102
-
103
-
104
-
105
37
  #質問
106
38
 
107
39
  テキストファイルに書かれている文字列の先頭を

5

余計なものを削除しました。

2018/11/30 06:47

投稿

detti0101
detti0101

スコア13

test CHANGED
File without changes
test CHANGED
@@ -44,8 +44,6 @@
44
44
 
45
45
  ```C#
46
46
 
47
- string txt = "サンプルです。";
48
-
49
47
  StreamReader text_file = new StreamReader(@"sample.txt", Encoding.GetEncoding("UTF-8"));
50
48
 
51
49
    string file = null;
@@ -68,19 +66,17 @@
68
66
 
69
67
  }
70
68
 
71
- txt += file + matsubi;
69
+ file += matsubi;
72
70
 
73
71
  }
74
72
 
75
- Console.WriteLine(txt);
73
+ Console.WriteLine(file);
76
74
 
77
75
  ```
78
76
 
79
77
  上記コードの結果
80
78
 
81
79
  =============
82
-
83
- サンプルです。
84
80
 
85
81
  テキストが書かれています。A
86
82
 
@@ -95,8 +91,6 @@
95
91
  ・最終的にしたいこと↓
96
92
 
97
93
  =============
98
-
99
- サンプルです。
100
94
 
101
95
  TESTテキストが書かれています。A
102
96
 

4

最終的にしたいことを追加

2018/11/30 06:43

投稿

detti0101
detti0101

スコア13

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,19 @@
8
8
 
9
9
 
10
10
 
11
+ 例)sample.txtの中身
12
+
13
+ =============
14
+
15
+ テキストが書かれています。
16
+
17
+ テキストが書かれています。
18
+
19
+ テキストが書かれています。
20
+
21
+ =============
22
+
11
- 例)
23
+
12
24
 
13
25
  =============
14
26
 
@@ -22,7 +34,7 @@
22
34
 
23
35
 
24
36
 
25
- #できていること
37
+ #できていること/最終目標
26
38
 
27
39
  テキストファイルを1行ずつ読み込んで表示しさらに
28
40
 
@@ -34,7 +46,7 @@
34
46
 
35
47
  string txt = "サンプルです。";
36
48
 
37
- StreamReader text_file = new StreamReader(@"テキストファイルパス", Encoding.GetEncoding("UTF-8"));
49
+ StreamReader text_file = new StreamReader(@"sample.txt", Encoding.GetEncoding("UTF-8"));
38
50
 
39
51
    string file = null;
40
52
 
@@ -80,6 +92,22 @@
80
92
 
81
93
 
82
94
 
95
+ ・最終的にしたいこと↓
96
+
97
+ =============
98
+
99
+ サンプルです。
100
+
101
+ TESTテキストが書かれています。A
102
+
103
+ テキストが書かれています。A
104
+
105
+ テキストが書かれています。
106
+
107
+ =============
108
+
109
+
110
+
83
111
  #質問
84
112
 
85
113
  テキストファイルに書かれている文字列の先頭を

3

質問を追加

2018/11/30 06:13

投稿

detti0101
detti0101

スコア13

test CHANGED
File without changes
test CHANGED
@@ -77,3 +77,17 @@
77
77
  テキストが書かれています。
78
78
 
79
79
  =============
80
+
81
+
82
+
83
+ #質問
84
+
85
+ テキストファイルに書かれている文字列の先頭を
86
+
87
+ 検知しそこに文字列を挿入する方法はありますか?
88
+
89
+ 調べても次の行に読み取り可能な文字があるなら"A"を表示
90
+
91
+ とかなら出てきますが先頭に表示するコードが
92
+
93
+ 見つかりませんでした。

2

文言を修正

2018/11/30 06:01

投稿

detti0101
detti0101

スコア13

test CHANGED
File without changes
test CHANGED
@@ -46,13 +46,13 @@
46
46
 
47
47
  string matsubi = "";
48
48
 
49
- //読み取り可能な文字があるなら"A"を表示
49
+ //次の行に読み取り可能な文字があるなら"A"を表示
50
50
 
51
51
  if (text_file.Peek() >= 0)
52
52
 
53
53
  {
54
54
 
55
- matsubi = "' A ";
55
+ matsubi = "A";
56
56
 
57
57
  }
58
58
 

1

変数を変更

2018/11/30 05:48

投稿

detti0101
detti0101

スコア13

test CHANGED
File without changes
test CHANGED
@@ -36,7 +36,7 @@
36
36
 
37
37
  StreamReader text_file = new StreamReader(@"テキストファイルパス", Encoding.GetEncoding("UTF-8"));
38
38
 
39
-   string user_id = null;
39
+   string file = null;
40
40
 
41
41
  while (text_file.Peek() != -1)
42
42