Like Operator not likeable

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

End Sub

Subject: Like Operator not likeable

I use something like

If fdNm$ Like "F#*" Then...

to look for “F203R2” and ignore “Form”. I like the simplicity of # vs [0-9].

But to your point of wanting to determine if every character in a string is a digit, have you tried IsNumeric?

Subject: RE: Like Operator not likeable

FYI: Becare if isNumeric, since i believe that values like 3e+10 or -3.09 is a valid number, but would fail in his case.

John

Subject: Like Operator not likeable

I’m not an expert with this function, but have you tried …

like “[!1-9]

This should be True is there’s any non-digit in the string, and False otherwise.

Subject: Like Operator not likeable

Graham wins the prize for the first part of my question. Thanks, Graham, and others.

The second part looks like a bug to me - what do you think?

Subject: RE: Like Operator not likeable

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

Subject: RE: Like Operator not likeable

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.