回答編集履歴

2

コードを部分修正

2024/07/02 21:03

投稿

TokoToko123
TokoToko123

スコア25

test CHANGED
@@ -30,10 +30,9 @@
30
30
  for (int index = 0; index < titles.Length; ++index)
31
31
  targets[index] = strComparate.Range(titles[index], "桁");
32
32
 
33
- int count = 0;
34
-
35
- foreach (string[] result in targets.Where(args => args[0] != args[1]))
33
+ for (int index = 0; index < titles.Length; ++index)
34
+ if (targets[index][0] != targets[index][1])
36
- WriteLine($"{titles[count++][0..3]}:比較文字A:{result[0]},比較文字B:{result[1]}");
35
+ WriteLine($"{titles[index][0..3]}:比較文字A:{targets[index][0]},比較文字B:{targets[index][1]}");
37
36
  }
38
37
  }
39
38
 
@@ -107,8 +106,9 @@
107
106
  ```
108
107
  「項目」のフォーマットが統一されていれば、固定の範囲から繰り返し必要な要素を取り出せます
109
108
  ```C#
110
- foreach (string[] result in targets.Where(args => args[0] != args[1]))
109
+ for (int index = 0; index < titles.Length; ++index)
110
+ if (targets[index][0] != targets[index][1])
111
- WriteLine($"{titles[count++][0..3]}:比較文字A:{result[0]},比較文字B:{result[1]}");
111
+ WriteLine($"{titles[index][0..3]}:比較文字A:{targets[index][0]},比較文字B:{targets[index][1]}");
112
112
  ```
113
113
  この方法は整数が必要数含まれていれば、どのような文字列にも対応できる利点がありますが、文字列解析のためのオーバーヘッドが発生する可能性があります
114
114
  またこのサンプルでは用意できる項目数がA~Zの範囲に限定されます

1

文章を修正

2024/07/02 20:37

投稿

TokoToko123
TokoToko123

スコア25

test CHANGED
@@ -1,4 +1,4 @@
1
- 「項目」から文字列の範囲を表す数値を取得するには[Regexクラス](https://learn.microsoft.com/ja-jp/dotnet/api/system.text.regularexpressions.regex?view=net-8.0)を使用します
1
+ 「項目」から文字列の範囲を表す数値を取得する手段として[Regexクラス](https://learn.microsoft.com/ja-jp/dotnet/api/system.text.regularexpressions.regex?view=net-8.0)を推奨します
2
2
  以下はサンプルです
3
3
 
4
4
  ```C#