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

回答編集履歴

1

GetHolidays関数の無駄なループ修正

2020/12/27 19:59

投稿

mah
mah

スコア598

answer CHANGED
@@ -75,42 +75,39 @@
75
75
 
76
76
  string result = "";
77
77
 
78
+ string date;
79
+ string week;
80
+
81
+ index = GetInnerText(source, index, dateTag, spanEndTag, date);
82
+ if (index < 0)
83
+ {
84
+ return result;
85
+ }
86
+
87
+ index = GetInnerText(source, index, weekTag, spanEndTag, week);
88
+ if (index < 0)
89
+ {
90
+ return result;
91
+ }
92
+
78
93
  while (true)
79
94
  {
80
- string date;
95
+ string country;
81
- string week;
96
+ string holiday;
82
97
 
83
- index = GetInnerText(source, index, dateTag, spanEndTag, date);
98
+ index = GetInnerText(source, index, countryTag, pEndTag, country);
84
99
  if (index < 0)
85
100
  {
86
- break;
101
+ return result;
87
102
  }
88
103
 
89
- index = GetInnerText(source, index, weekTag, spanEndTag, week);
104
+ index = GetInnerText(source, index, holidayTag, pEndTag, holiday);
90
105
  if (index < 0)
91
106
  {
92
- break;
107
+ return result;
93
108
  }
94
109
 
95
- while (true)
96
- {
97
- string country;
98
- string holiday;
99
-
100
- index = GetInnerText(source, index, countryTag, pEndTag, country);
101
- if (index < 0)
102
- {
103
- return result;
104
- }
105
-
106
- index = GetInnerText(source, index, holidayTag, pEndTag, holiday);
107
- if (index < 0)
108
- {
109
- return result;
110
- }
111
-
112
- result += StringFormat("%s %s %s %s\n", date, week, country, holiday);
110
+ result += StringFormat("%s %s %s %s\n", date, week, country, holiday);
113
- }
114
111
  }
115
112
 
116
113
  return result;