3

If ステートメントで 2 つの変数を比較する必要がありますが、ケースを除いてすべてが同じである場合は、true を返す必要があります。私はこれを書くことができないことを知っていますが、ここに私がやろうとしていることの感覚があります:

If (str1=str2 matchcase:=false) then

何か案は?ありがとう

4

3 に答える 3

5

私は@mr.Rebandの回答を好みますが、StrComp関数を使用するこの代替案を参照することもできます。

Sub test()

Dim str1 As String
Dim str2 As String

str1 = "test"
str2 = "Test"

MsgBox StrComp(str1, str2, vbTextCompare)


'Return Values
'
'The StrComp function has the following return values:
'
'If StrComp returns
'string1 is less than string2 -1
'string1 is equal to string2 0
'string1 is greater than string2 1
'string1 or string2 is Null Null

End Sub
于 2013-09-30T16:34:15.460 に答える
3

最速を求める場合は、StrComp() を使用することをお勧めします。

StrComp は、実際に文字列または文字列全体を比較する必要がないようにいくつかのテストを行い、文字列が異なる場合に高速化します。多くの一般的な値が予想される場合は、StrComp を避けることができますが、ほとんどの場合、StrComp の方が高速です。

100M comparisons with same phrase but different case:
LCase = 20 seconds
StrComp = 23 seconds *This is a rare case

100M comparisons with different phrase but same length
LCase = 20 seconds
StrComp = 9 seconds

100M comparisons with different phrase and different length
LCase = 25 seconds
StrComp = 9 seconds

注: 文字列の長さによって結果が異なります。たとえば、最後のテストでは、文字列の 1 つの長さを 2 倍にしたため、LCase は他のテストよりも時間がかかりました。これにより LCase は遅くなりましたが、StrComp は遅くなりませんでした。

注 2: LCase と UCase は同様の結果でした。

于 2013-09-30T18:27:21.530 に答える