回答編集履歴

5

コード修正

2018/06/09 15:10

投稿

hatena19
hatena19

スコア33620

test CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  With reg
24
24
 
25
- .Pattern = "もも|パイナップル|みかん|バナナ|檸檬"
25
+ .Pattern = "|パイナップル|みかん|バナナ|檸檬"
26
26
 
27
27
  .IgnoreCase = True
28
28
 
@@ -66,7 +66,7 @@
66
66
 
67
67
 
68
68
 
69
- Const 検索パターン = "もも|パイナップル|みかん|バナナ|檸檬"
69
+ Const 検索パターン = "|パイナップル|みかん|バナナ|檸檬"
70
70
 
71
71
 
72
72
 

4

書式の改善

2018/06/09 15:10

投稿

hatena19
hatena19

スコア33620

test CHANGED
@@ -48,7 +48,7 @@
48
48
 
49
49
  テストしてみました
50
50
 
51
- ---
51
+ ---
52
52
 
53
53
  時間の計測は、[VBAでミリ秒以下の高精度で処理時間計測](https://hatenachips.blog.fc2.com/blog-entry-377.html) の関数を使いました。マイクロ秒の精度で計測てきますので、ループさせる必要なく計測できます。
54
54
 

3

編集時に間違って必要な部分も上書きしてしまったので修正

2018/06/09 14:39

投稿

hatena19
hatena19

スコア33620

test CHANGED
@@ -2,21 +2,73 @@
2
2
 
3
3
 
4
4
 
5
- ~~Like演算子は前にテストした時は、InStrより遅かったです。~~(今回テストしたら違った結果になりました。)
5
+ Like演算子は前にテストした時は、InStrより遅かったです。
6
6
 
7
7
  RegExpはやったことがないので、テストした結果を教えてほしいです。
8
8
 
9
-
9
+ ```vba
10
+
11
+ Public Sub fruits_check()
12
+
13
+ Dim 判定対象文字列 As String
14
+
15
+ Dim reg As Object
16
+
17
+
18
+
19
+ Set reg = CreateObject("VBScript.RegExp")
20
+
21
+
22
+
23
+ With reg
24
+
25
+ .Pattern = "もも|パイナップル|みかん|バナナ|檸檬"
26
+
27
+ .IgnoreCase = True
28
+
29
+ .Global = False
30
+
31
+ End With
32
+
33
+
34
+
35
+ 判定対象文字列 = "あああああああ檸檬ああああああ"
36
+
37
+
38
+
39
+ If reg.Test(判定対象文字列) Then MsgBox "ありました"
40
+
41
+
42
+
43
+ End Sub
44
+
45
+ ```
46
+
47
+
48
+
49
+ テストしてみました
50
+
51
+ ---
52
+
53
+ 時間の計測は、[VBAでミリ秒以下の高精度で処理時間計測](https://hatenachips.blog.fc2.com/blog-entry-377.html) の関数を使いました。マイクロ秒の精度で計測てきますので、ループさせる必要なく計測できます。
54
+
55
+ 判定対象文字列は、Wikipedia:引用のガイドラインから5500字エディターにコピーして真ん中ぐらいに「檸檬」を挿入しました。それをA1セルにコピペしました。
56
+
57
+ 実行環境:Windows 10 Home 64bit / Microsoft Excel 2016 32bit
58
+
59
+
60
+
61
+ **テストコード**
10
62
 
11
63
  ```vba
12
64
 
13
65
  Public Sub fruits_check()
14
66
 
15
-
67
+
16
68
 
17
69
  Const 検索パターン = "もも|パイナップル|みかん|バナナ|檸檬"
18
70
 
19
-
71
+
20
72
 
21
73
  Dim くだもの判定(5) As String
22
74
 
@@ -30,19 +82,19 @@
30
82
 
31
83
  くだもの判定(5) = "檸檬"
32
84
 
33
-
85
+
34
86
 
35
87
  Dim 判定対象文字列 As String
36
88
 
37
89
  判定対象文字列 = Range("A1").Value
38
90
 
39
-
91
+
40
92
 
41
93
  Dim lateReg As Object
42
94
 
43
95
  Set lateReg = CreateObject("VBScript.RegExp")
44
96
 
45
-
97
+
46
98
 
47
99
  Dim earlyReg As RegExp
48
100
 
@@ -50,191 +102,109 @@
50
102
 
51
103
 
52
104
 
53
- Dim result As Boolean, i As Long
54
-
55
-
56
-
57
- SWStart
58
-
59
- With lateReg
60
-
61
- .Pattern = 検索パターン
62
-
63
- .IgnoreCase = True
64
-
65
- .Global = False
66
-
67
- result = .Test(判定対象文字列)
68
-
69
- End With
70
-
71
- SWStop
72
-
73
- SWShow "lateReg : " & result & " "
74
-
75
-
76
-
77
- result = False
78
-
79
- SWStart
80
-
81
- With earlyReg
82
-
83
- .Pattern = 検索パターン
84
-
85
- .IgnoreCase = True
86
-
87
- .Global = False
88
-
89
- result = .Test(判定対象文字列)
90
-
91
- End With
92
-
93
- SWStop
94
-
95
- SWShow "earlyReg: " & result & " "
96
-
97
-
98
-
99
- result = False
100
-
101
- SWStart
102
-
103
- For i = 1 To 5
104
-
105
- If (InStr(判定対象文字列, くだもの判定(i)) > 0) Then
106
-
107
- result = True
108
-
109
- Exit For
110
-
111
- End If
112
-
113
- Next i
114
-
115
- SWStop
116
-
117
- SWShow "InStr : " & result & " "
118
-
119
-
120
-
121
- result = False
122
-
123
- SWStart
124
-
125
- For i = 1 To 5
126
-
127
- If 判定対象文字列 Like "*" & くだもの判定(i) & "*" Then
128
-
129
- result = True
130
-
131
- Exit For
132
-
133
- End If
134
-
135
- Next i
136
-
137
- SWStop
138
-
139
- SWShow "Like : " & result & " "
140
-
141
-
142
-
143
- '一致なし用のサンプルデータ
144
-
145
- 判定対象文字列 = Replace(判定対象文字列, "檸檬", "")
146
-
147
- Debug.Print ""
148
-
149
-
150
-
151
- result = False
152
-
153
- SWStart
154
-
155
- With lateReg
156
-
157
- .Pattern = 検索パターン
158
-
159
- .IgnoreCase = True
160
-
161
- .Global = False
162
-
163
- result = .Test(判定対象文字列)
164
-
165
- End With
166
-
167
- SWStop
168
-
169
- SWShow "lateReg : " & result & " "
170
-
171
-
172
-
173
- result = False
174
-
175
- SWStart
176
-
177
- With earlyReg
178
-
179
- .Pattern = 検索パターン
180
-
181
- .IgnoreCase = True
182
-
183
- .Global = False
184
-
185
- result = .Test(判定対象文字列)
186
-
187
- End With
188
-
189
- SWStop
190
-
191
- SWShow "earlyReg: " & result & " "
192
-
193
-
194
-
195
- result = False
196
-
197
- SWStart
198
-
199
- For i = 1 To 5
200
-
201
- If (InStr(1, 判定対象文字列, くだもの判定(i), vbBinaryCompare) > 0) Then
202
-
203
- result = True
204
-
205
- Exit For
206
-
207
- End If
208
-
209
- Next i
210
-
211
- SWStop
212
-
213
- SWShow "InStr : " & result & " "
214
-
215
-
216
-
217
- result = False
218
-
219
- SWStart
220
-
221
- For i = 1 To 5
222
-
223
- If 判定対象文字列 Like "*" & くだもの判定(i) & "*" Then
224
-
225
- result = True
226
-
227
- Exit For
228
-
229
- End If
230
-
231
- Next i
232
-
233
- SWStop
234
-
235
- SWShow "Like : " & result & " "
236
-
237
-
105
+ Dim result As Boolean, i As Long, j As Long
106
+
107
+
108
+
109
+ For j = 1 To 2
110
+
111
+ result = False
112
+
113
+ SWStart
114
+
115
+ With lateReg
116
+
117
+ .Pattern = 検索パターン
118
+
119
+ .IgnoreCase = True
120
+
121
+ .Global = False
122
+
123
+ result = .Test(判定対象文字列)
124
+
125
+ End With
126
+
127
+ SWStop
128
+
129
+ SWShow "lateReg : " & result & " "
130
+
131
+
132
+
133
+ result = False
134
+
135
+ SWStart
136
+
137
+ With earlyReg
138
+
139
+ .Pattern = 検索パターン
140
+
141
+ .IgnoreCase = True
142
+
143
+ .Global = False
144
+
145
+ result = .Test(判定対象文字列)
146
+
147
+ End With
148
+
149
+ SWStop
150
+
151
+ SWShow "earlyReg: " & result & " "
152
+
153
+
154
+
155
+ result = False
156
+
157
+ SWStart
158
+
159
+ For i = 1 To 5
160
+
161
+ If (InStr(判定対象文字列, くだもの判定(i)) > 0) Then
162
+
163
+ result = True
164
+
165
+ Exit For
166
+
167
+ End If
168
+
169
+ Next i
170
+
171
+ SWStop
172
+
173
+ SWShow "InStr : " & result & " "
174
+
175
+
176
+
177
+ result = False
178
+
179
+ SWStart
180
+
181
+ For i = 1 To 5
182
+
183
+ If 判定対象文字列 Like "*" & くだもの判定(i) & "*" Then
184
+
185
+ result = True
186
+
187
+ Exit For
188
+
189
+ End If
190
+
191
+ Next i
192
+
193
+ SWStop
194
+
195
+ SWShow "Like : " & result & " "
196
+
197
+
198
+
199
+ '一致なし用のサンプルデータ
200
+
201
+ 判定対象文字列 = Replace(判定対象文字列, "檸檬", "")
202
+
203
+ Debug.Print ""
204
+
205
+ Next j
206
+
207
+
238
208
 
239
209
  End Sub
240
210
 
@@ -266,6 +236,8 @@
266
236
 
267
237
  ```
268
238
 
239
+
240
+
269
241
  単位はミリ秒です。
270
242
 
271
243
  当方の環境、用意したサンプルでは、InStrが最も速いという結果になりました。

2

コードの修正

2018/06/09 14:37

投稿

hatena19
hatena19

スコア33620

test CHANGED
@@ -12,35 +12,229 @@
12
12
 
13
13
  Public Sub fruits_check()
14
14
 
15
+
16
+
17
+ Const 検索パターン = "もも|パイナップル|みかん|バナナ|檸檬"
18
+
19
+
20
+
21
+ Dim くだもの判定(5) As String
22
+
23
+ くだもの判定(1) = "桃"
24
+
25
+ くだもの判定(2) = "パイナップル"
26
+
27
+ くだもの判定(3) = "みかん"
28
+
29
+ くだもの判定(4) = "バナナ"
30
+
31
+ くだもの判定(5) = "檸檬"
32
+
33
+
34
+
15
35
  Dim 判定対象文字列 As String
16
36
 
17
- Dim reg As Object
18
-
19
-
20
-
21
- Set reg = CreateObject("VBScript.RegExp")
22
-
23
-
24
-
25
- With reg
26
-
27
- .Pattern = "もも|パイナップル|みかん|バナナ|檸檬"
28
-
29
- .IgnoreCase = True
30
-
31
- .Global = False
32
-
33
- End With
34
-
35
-
36
-
37
- 判定対象文字列 = "あああああああ檸檬ああああああ"
38
-
39
-
40
-
41
- If reg.Test(判定対象文字列) Then MsgBox "ありました"
42
-
43
-
37
+ 判定対象文字列 = Range("A1").Value
38
+
39
+
40
+
41
+ Dim lateReg As Object
42
+
43
+ Set lateReg = CreateObject("VBScript.RegExp")
44
+
45
+
46
+
47
+ Dim earlyReg As RegExp
48
+
49
+ Set earlyReg = New RegExp
50
+
51
+
52
+
53
+ Dim result As Boolean, i As Long
54
+
55
+
56
+
57
+ SWStart
58
+
59
+ With lateReg
60
+
61
+ .Pattern = 検索パターン
62
+
63
+ .IgnoreCase = True
64
+
65
+ .Global = False
66
+
67
+ result = .Test(判定対象文字列)
68
+
69
+ End With
70
+
71
+ SWStop
72
+
73
+ SWShow "lateReg : " & result & " "
74
+
75
+
76
+
77
+ result = False
78
+
79
+ SWStart
80
+
81
+ With earlyReg
82
+
83
+ .Pattern = 検索パターン
84
+
85
+ .IgnoreCase = True
86
+
87
+ .Global = False
88
+
89
+ result = .Test(判定対象文字列)
90
+
91
+ End With
92
+
93
+ SWStop
94
+
95
+ SWShow "earlyReg: " & result & " "
96
+
97
+
98
+
99
+ result = False
100
+
101
+ SWStart
102
+
103
+ For i = 1 To 5
104
+
105
+ If (InStr(判定対象文字列, くだもの判定(i)) > 0) Then
106
+
107
+ result = True
108
+
109
+ Exit For
110
+
111
+ End If
112
+
113
+ Next i
114
+
115
+ SWStop
116
+
117
+ SWShow "InStr : " & result & " "
118
+
119
+
120
+
121
+ result = False
122
+
123
+ SWStart
124
+
125
+ For i = 1 To 5
126
+
127
+ If 判定対象文字列 Like "*" & くだもの判定(i) & "*" Then
128
+
129
+ result = True
130
+
131
+ Exit For
132
+
133
+ End If
134
+
135
+ Next i
136
+
137
+ SWStop
138
+
139
+ SWShow "Like : " & result & " "
140
+
141
+
142
+
143
+ '一致なし用のサンプルデータ
144
+
145
+ 判定対象文字列 = Replace(判定対象文字列, "檸檬", "")
146
+
147
+ Debug.Print ""
148
+
149
+
150
+
151
+ result = False
152
+
153
+ SWStart
154
+
155
+ With lateReg
156
+
157
+ .Pattern = 検索パターン
158
+
159
+ .IgnoreCase = True
160
+
161
+ .Global = False
162
+
163
+ result = .Test(判定対象文字列)
164
+
165
+ End With
166
+
167
+ SWStop
168
+
169
+ SWShow "lateReg : " & result & " "
170
+
171
+
172
+
173
+ result = False
174
+
175
+ SWStart
176
+
177
+ With earlyReg
178
+
179
+ .Pattern = 検索パターン
180
+
181
+ .IgnoreCase = True
182
+
183
+ .Global = False
184
+
185
+ result = .Test(判定対象文字列)
186
+
187
+ End With
188
+
189
+ SWStop
190
+
191
+ SWShow "earlyReg: " & result & " "
192
+
193
+
194
+
195
+ result = False
196
+
197
+ SWStart
198
+
199
+ For i = 1 To 5
200
+
201
+ If (InStr(1, 判定対象文字列, くだもの判定(i), vbBinaryCompare) > 0) Then
202
+
203
+ result = True
204
+
205
+ Exit For
206
+
207
+ End If
208
+
209
+ Next i
210
+
211
+ SWStop
212
+
213
+ SWShow "InStr : " & result & " "
214
+
215
+
216
+
217
+ result = False
218
+
219
+ SWStart
220
+
221
+ For i = 1 To 5
222
+
223
+ If 判定対象文字列 Like "*" & くだもの判定(i) & "*" Then
224
+
225
+ result = True
226
+
227
+ Exit For
228
+
229
+ End If
230
+
231
+ Next i
232
+
233
+ SWStop
234
+
235
+ SWShow "Like : " & result & " "
236
+
237
+
44
238
 
45
239
  End Sub
46
240
 
@@ -48,260 +242,30 @@
48
242
 
49
243
 
50
244
 
51
- テストしてみました
52
-
53
- ---
54
-
55
- 時間の計測は、[VBAでミリ秒以下の高精度で処理時間計測](https://hatenachips.blog.fc2.com/blog-entry-377.html) の関数を使いました。マイクロ秒の精度で計測てきますので、ループさせる必要なく計測できます。
56
-
57
- 判定対象文字列は、Wikipedia:引用のガイドラインから5500字エディターにコピーして真ん中ぐらいに「檸檬」を挿入しました。それをA1セルにコピペしました。
58
-
59
- 実行環境:Windows 10 Home 64bit / Microsoft Excel 2016 32bit
60
-
61
-
62
-
63
- **テストコード**
64
-
65
- ```vba
66
-
67
- Public Sub fruits_check()
68
-
69
-
70
-
71
- Const 検索パターン = "もも|パイナップル|みかん|バナナ|檸檬"
72
-
73
-
74
-
75
- Dim くだもの判定(5) As String
76
-
77
- くだもの判定(1) = "桃"
78
-
79
- くだもの判定(2) = "パイナップル"
80
-
81
- くだもの判定(3) = "みかん"
82
-
83
- くだもの判定(4) = "バナナ"
84
-
85
- くだもの判定(5) = "檸檬"
86
-
87
-
88
-
89
- Dim 判定対象文字列 As String
90
-
91
- 判定対象文字列 = Range("A1").Value
92
-
93
-
94
-
95
- Dim lateReg As Object
96
-
97
- Set lateReg = CreateObject("VBScript.RegExp")
98
-
99
-
100
-
101
- Dim earlyReg As RegExp
102
-
103
- Set earlyReg = New RegExp
104
-
105
-
106
-
107
- Dim result As Boolean, i As Long
108
-
109
-
110
-
111
- SWStart
112
-
113
- With lateReg
114
-
115
- .Pattern = 検索パターン
116
-
117
- .IgnoreCase = True
118
-
119
- .Global = False
120
-
121
- result = .Test(判定対象文字列)
122
-
123
- End With
124
-
125
- SWStop
126
-
127
- SWShow "lateReg : " & result & " "
128
-
129
-
130
-
131
- SWStart
132
-
133
- With earlyReg
134
-
135
- .Pattern = 検索パターン
136
-
137
- .IgnoreCase = True
138
-
139
- .Global = False
140
-
141
- result = .Test(判定対象文字列)
142
-
143
- End With
144
-
145
- SWStop
146
-
147
- SWShow "earlyReg: " & result & " "
148
-
149
-
150
-
151
- SWStart
152
-
153
- For i = 1 To 5
154
-
155
- If (InStr(判定対象文字列, くだもの判定(i)) > 0) Then
156
-
157
- result = True
158
-
159
- Exit For
160
-
161
- End If
162
-
163
- Next i
164
-
165
- SWStop
166
-
167
- SWShow "InStr : " & result & " "
168
-
169
-
170
-
171
- SWStart
172
-
173
- For i = 1 To 5
174
-
175
- If 判定対象文字列 Like くだもの判定(i) Then
176
-
177
- result = True
178
-
179
- Exit For
180
-
181
- End If
182
-
183
- Next i
184
-
185
- SWStop
186
-
187
- SWShow "Like : " & result & " "
188
-
189
-
190
-
191
- 判定対象文字列 = Replace(判定対象文字列, "檸檬", "")
192
-
193
- Debug.Print ""
194
-
195
-
196
-
197
- SWStart
198
-
199
- With lateReg
200
-
201
- .Pattern = 検索パターン
202
-
203
- .IgnoreCase = True
204
-
205
- .Global = False
206
-
207
- result = .Test(判定対象文字列)
208
-
209
- End With
210
-
211
- SWStop
212
-
213
- SWShow "lateReg : " & result & " "
214
-
215
-
216
-
217
- SWStart
218
-
219
- With earlyReg
220
-
221
- .Pattern = 検索パターン
222
-
223
- .IgnoreCase = True
224
-
225
- .Global = False
226
-
227
- result = .Test(判定対象文字列)
228
-
229
- End With
230
-
231
- SWStop
232
-
233
- SWShow "earlyReg: " & result & " "
234
-
235
-
236
-
237
- SWStart
238
-
239
- For i = 1 To 5
240
-
241
- If (InStr(判定対象文字列, くだもの判定(i)) > 0) Then
242
-
243
- result = True
244
-
245
- Exit For
246
-
247
- End If
248
-
249
- Next i
250
-
251
- SWStop
252
-
253
- SWShow "InStr : " & result & " "
254
-
255
-
256
-
257
- SWStart
258
-
259
- For i = 1 To 5
260
-
261
- If 判定対象文字列 Like くだもの判定(i) Then
262
-
263
- result = True
264
-
265
- Exit For
266
-
267
- End If
268
-
269
- Next i
270
-
271
- SWStop
272
-
273
- SWShow "Like : " & result & " "
274
-
275
- End Sub
245
+ **計測結果**
246
+
247
+ ```text
248
+
249
+ lateReg : True 1.0089
250
+
251
+ earlyReg: True 0.6539
252
+
253
+ InStr : True 0.0472
254
+
255
+ Like : True 0.0526
256
+
257
+
258
+
259
+ lateReg : False 1.5676
260
+
261
+ earlyReg: False 1.2376
262
+
263
+ InStr : False 0.0501
264
+
265
+ Like : False 0.0558
276
266
 
277
267
  ```
278
268
 
279
-
280
-
281
- **計測結果**
282
-
283
- ```text
284
-
285
- lateReg : True 1.08
286
-
287
- earlyReg: True 1.0607
288
-
289
- InStr : True 0.0694
290
-
291
- Like : True 0.0034
292
-
293
-
294
-
295
- lateReg : False 2.5398
296
-
297
- earlyReg: False 2.0252
298
-
299
- InStr : False 0.0751
300
-
301
- Like : False 0.0031
302
-
303
- ```
304
-
305
269
  単位はミリ秒です。
306
270
 
307
- 当方の環境、用意したサンプルでは、圧倒的にLikeが速いという結果になりました。
271
+ 当方の環境、用意したサンプルでは、InStr最も速いという結果になりました。

1

テストコードの追加

2018/06/09 14:25

投稿

hatena19
hatena19

スコア33620

test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- Like演算子は前にテストした時は、InStrより遅かったです。
5
+ ~~Like演算子は前にテストした時は、InStrより遅かったです。~~(今回テストしたら違った結果になりました。)
6
6
 
7
7
  RegExpはやったことがないので、テストした結果を教えてほしいです。
8
8
 
@@ -45,3 +45,263 @@
45
45
  End Sub
46
46
 
47
47
  ```
48
+
49
+
50
+
51
+ テストしてみました
52
+
53
+ ---
54
+
55
+ 時間の計測は、[VBAでミリ秒以下の高精度で処理時間計測](https://hatenachips.blog.fc2.com/blog-entry-377.html) の関数を使いました。マイクロ秒の精度で計測てきますので、ループさせる必要なく計測できます。
56
+
57
+ 判定対象文字列は、Wikipedia:引用のガイドラインから5500字エディターにコピーして真ん中ぐらいに「檸檬」を挿入しました。それをA1セルにコピペしました。
58
+
59
+ 実行環境:Windows 10 Home 64bit / Microsoft Excel 2016 32bit
60
+
61
+
62
+
63
+ **テストコード**
64
+
65
+ ```vba
66
+
67
+ Public Sub fruits_check()
68
+
69
+
70
+
71
+ Const 検索パターン = "もも|パイナップル|みかん|バナナ|檸檬"
72
+
73
+
74
+
75
+ Dim くだもの判定(5) As String
76
+
77
+ くだもの判定(1) = "桃"
78
+
79
+ くだもの判定(2) = "パイナップル"
80
+
81
+ くだもの判定(3) = "みかん"
82
+
83
+ くだもの判定(4) = "バナナ"
84
+
85
+ くだもの判定(5) = "檸檬"
86
+
87
+
88
+
89
+ Dim 判定対象文字列 As String
90
+
91
+ 判定対象文字列 = Range("A1").Value
92
+
93
+
94
+
95
+ Dim lateReg As Object
96
+
97
+ Set lateReg = CreateObject("VBScript.RegExp")
98
+
99
+
100
+
101
+ Dim earlyReg As RegExp
102
+
103
+ Set earlyReg = New RegExp
104
+
105
+
106
+
107
+ Dim result As Boolean, i As Long
108
+
109
+
110
+
111
+ SWStart
112
+
113
+ With lateReg
114
+
115
+ .Pattern = 検索パターン
116
+
117
+ .IgnoreCase = True
118
+
119
+ .Global = False
120
+
121
+ result = .Test(判定対象文字列)
122
+
123
+ End With
124
+
125
+ SWStop
126
+
127
+ SWShow "lateReg : " & result & " "
128
+
129
+
130
+
131
+ SWStart
132
+
133
+ With earlyReg
134
+
135
+ .Pattern = 検索パターン
136
+
137
+ .IgnoreCase = True
138
+
139
+ .Global = False
140
+
141
+ result = .Test(判定対象文字列)
142
+
143
+ End With
144
+
145
+ SWStop
146
+
147
+ SWShow "earlyReg: " & result & " "
148
+
149
+
150
+
151
+ SWStart
152
+
153
+ For i = 1 To 5
154
+
155
+ If (InStr(判定対象文字列, くだもの判定(i)) > 0) Then
156
+
157
+ result = True
158
+
159
+ Exit For
160
+
161
+ End If
162
+
163
+ Next i
164
+
165
+ SWStop
166
+
167
+ SWShow "InStr : " & result & " "
168
+
169
+
170
+
171
+ SWStart
172
+
173
+ For i = 1 To 5
174
+
175
+ If 判定対象文字列 Like くだもの判定(i) Then
176
+
177
+ result = True
178
+
179
+ Exit For
180
+
181
+ End If
182
+
183
+ Next i
184
+
185
+ SWStop
186
+
187
+ SWShow "Like : " & result & " "
188
+
189
+
190
+
191
+ 判定対象文字列 = Replace(判定対象文字列, "檸檬", "")
192
+
193
+ Debug.Print ""
194
+
195
+
196
+
197
+ SWStart
198
+
199
+ With lateReg
200
+
201
+ .Pattern = 検索パターン
202
+
203
+ .IgnoreCase = True
204
+
205
+ .Global = False
206
+
207
+ result = .Test(判定対象文字列)
208
+
209
+ End With
210
+
211
+ SWStop
212
+
213
+ SWShow "lateReg : " & result & " "
214
+
215
+
216
+
217
+ SWStart
218
+
219
+ With earlyReg
220
+
221
+ .Pattern = 検索パターン
222
+
223
+ .IgnoreCase = True
224
+
225
+ .Global = False
226
+
227
+ result = .Test(判定対象文字列)
228
+
229
+ End With
230
+
231
+ SWStop
232
+
233
+ SWShow "earlyReg: " & result & " "
234
+
235
+
236
+
237
+ SWStart
238
+
239
+ For i = 1 To 5
240
+
241
+ If (InStr(判定対象文字列, くだもの判定(i)) > 0) Then
242
+
243
+ result = True
244
+
245
+ Exit For
246
+
247
+ End If
248
+
249
+ Next i
250
+
251
+ SWStop
252
+
253
+ SWShow "InStr : " & result & " "
254
+
255
+
256
+
257
+ SWStart
258
+
259
+ For i = 1 To 5
260
+
261
+ If 判定対象文字列 Like くだもの判定(i) Then
262
+
263
+ result = True
264
+
265
+ Exit For
266
+
267
+ End If
268
+
269
+ Next i
270
+
271
+ SWStop
272
+
273
+ SWShow "Like : " & result & " "
274
+
275
+ End Sub
276
+
277
+ ```
278
+
279
+
280
+
281
+ **計測結果**
282
+
283
+ ```text
284
+
285
+ lateReg : True 1.08
286
+
287
+ earlyReg: True 1.0607
288
+
289
+ InStr : True 0.0694
290
+
291
+ Like : True 0.0034
292
+
293
+
294
+
295
+ lateReg : False 2.5398
296
+
297
+ earlyReg: False 2.0252
298
+
299
+ InStr : False 0.0751
300
+
301
+ Like : False 0.0031
302
+
303
+ ```
304
+
305
+ 単位はミリ秒です。
306
+
307
+ 当方の環境、用意したサンプルでは、圧倒的にLikeが速いという結果になりました。