Re: Like Statement

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Jonathan West (jwest_at_mvps.org)
Date: 01/15/05


Date: Sat, 15 Jan 2005 21:47:08 -0000

Hi Greg,

I think you didn't notice the ! character in the comparison string, or
perhaps didn't understand the significance of it. Comparing with "*[!a-z]*"
will return True if the string being checked contains any character that is
not in the range a-z. Therefore it returns False if the string is _all_
lowercase characters. Invert that result for the IsLowerCase function.

Comparing with "*[a-z]*" returns True if the string contains any character
that *is* in the range a-z. This of course will return true if the string is
mixed as well as all lowercase. My understanding is that you want a function
that return True only of all the characters are lowercase.

By the way, I didn't test the function on a zero-length string. As it
happens it returns True for a zero-length string. You'll have to decide if
that is an appropriate result - if not, you'll need to put in an extra test
for a zero-length string

-- 
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
"Greg Maxey" <gmaxey@mvps.OscarRomeoGolf> wrote in message 
news:%23LRPDtm%23EHA.4092@TK2MSFTNGP09.phx.gbl...
> Johnathan,
>
> This certainly works, but I can't get my head around why it works when:
>
> strIn Like "*[a-z]*" won't work.
>
> It seems your method is saying if zero or more characters from the start 
> or zero or more chacters endd is not a letter a-z then the Like Statement 
> is false and the Not Like statement is true.
>
> Wait a minute, perhaps the fog is clearing.
>
> So "*[a-z]*" would mean if zero or more characters from the start or zero 
> or more chacters end "are" a letter a-z then the statement is true.
>
> strIn = "abc5xyz"
> So strIn Like "abc5xyz" would meet that condition and correctly (while 
> seemingly erroneous) return a True.
>
> I think this how this works.  If you have time would you confirm or offer 
> the correct explanation.
>
> Thanks.
> -- 
> Greg Maxey/Word MVP
> A Peer in Peer to Peer Support
>
> Jonathan West wrote:
>> "Helmut Weber" <elmkqznfwvccbf@mailinator.com> wrote in message
>> news:23afu059co7nbddp9fj9l2are9sir3uaoc@4ax.com...
>>> Hi Greg,
>>>> I want my Like statement to be true if the string is only lower case
>>>> letters.
>>> hmm...
>>>
>>> Dim s As String
>>> s = "abcdefghijklmnopQrstuvwxyz"
>>> If LCase(s) = s Then
>>>   MsgBox "yes"
>>> Else
>>>   MsgBox "no"
>>> End If
>>
>> Hi Helmut
>>
>> You might like to check the result of this...
>>
>> Dim s As String
>> s = "1234567890-*$£^"
>> If LCase(s) = s Then
>>   MsgBox "yes"
>> Else
>>   MsgBox "no"
>> End If
>>
>>
>> Again, the solution can be achieved using the Like operator. This
>> function will do the needful
>>
>> Function IsLowerCase(strIn As String) As Boolean
>>  IsLowerCase = Not strIn Like "*[!a-z]*"
>> End Function
>
> 


Relevant Pages

  • Re: How to convert Infix notation to postfix notation
    ... If this is for an error message, why isn't it using stderr for its output? ... array of 15 characters, and you call this function with the limit 15 on ... Making sure that the only string I allocate and append to, ... because mulFactor in all versions must needs incorporate the functions ...
    (comp.lang.c)
  • Re: Prothon should not borrow Python strings!
    ... """It does not make sense to have a string without knowing what encoding ... same cul de sac as Python. ... Prothon_String_As_ASCII // raises error if there are high characters ... Python's split between byte strings and Unicode strings is ...
    (comp.lang.python)
  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... put them in stupid places. ... Programming is difficult (as you must surely appreciate, ... > strings will be in the range 1...1000 characters. ... impose an artificially small limit on string length." ...
    (comp.programming)
  • Re: Fast UTF-8 strlen function
    ... >> Is there a fast UTF-8 string length function floating around? ... Length in bytes, or length in characters? ... For UTF-8, the main basic "change" you have to make to your string routines ... then I could individually look up the characters in my UNICODE ...
    (alt.lang.asm)
  • Re: Byte Array to String
    ... retrieved text will mismatch the original characters. ... encoding the characters. ... Dim strFileData as String ...
    (microsoft.public.dotnet.framework.aspnet)