I have two problems with the Like operator in LotusScript. First, I would like to determine that every character in a string is a digit. Like [0-9]* evaluates True if the first character is a digit, followed by any sequence of letters, numbers, or symbols (8abcd is True). I would like 12345 to be True, but 123X45 False. I realize this is not RegEx, but is there a way to do it with Like?
Second, and this is more strange to me, Like [a-z] evaluates True with a capital A, even with Option Compare Case turned on.
Here’s my test code:
Sub Initialize
i$ = Inputbox$("Is this numeric?","Enter a Number")
If i$ Like "[0-9]*" Then
Msgbox i$ & " is numeric", ,i$
Else
Msgbox i$ & " is not numeric", , i$
End If
i$ = Inputbox$("Is this text?","Enter a Character")
If i$ Like "[a-z]" Then
Msgbox i$ & " is lower case text", ,i$
Else
Msgbox i$ & " is not lower case text", , i$
End If
well on the surface it would appear to be a bug but I cannot think that nobody else has not brought this up before now because it seems like something that might be used quite frequently. I think I found you a workaround though:
Dim ret As Variant
i$ = Inputbox$("Is this text?","Enter a Character")
ret = Evaluate( | @Matches( "| + i$ + |" ;"+{a-z}") | )
If ret(0) Then
Msgbox i$ & " is lower case text", ,i$
Else
Msgbox i$ & " is not lower case text", , i$
End If
You’re assuming that the collating sequence has all the lowercase letters together in a group, and all the uppercase letters together in another group, as in ANSI sequencing. In fact, it appears the default collating sequence has the lowercase and uppercase letters interleaved (aAbBcCdD…), so that e.g. “d” is in the range “A-Z”. You can see this for yourself with this script:
Dim r
r = Split(“a,D,C,B,b,A,c,d”, “,”)
Dim i%, k%, x$
For i = 0 To Ubound(r)-1
For k = i+1 To Ubound(r)
If r(i) > r(k) Then
x = r(i)
r(i) = r(k)
r(k) = x
End If
Next
Next
Print Join(r, “”)
If you want to use ANSI sequencing, you can do so by specifying Option Compare Binary.
Alternately, you can test for something being an uppercase letter by [ABCDEFGHIJKLMNOPQRSTUVWXYZ].
If you are about to say that this is surprising and contrary to the documentation, I agree, but at least the behavior is explained.