Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Inlist() comparison question
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00393021
Message ID:
00393030
Views:
18
Yes, but you would need to pad with spaces. For example, consider a two-character blood-type field cBloodType being validated against A, B, AB, and 0. To use INSTRING, you would do INSTRING( cBloodType, "A B ABO "). Since the length of cBloodType is two characters, the validation string is treated as "A ", "B ", "AB", and "O ". You could also use PADR( ALLTRIM( cBloodType), 2) as the first parameter to insure the correct comparison length and a trailing space where needed.

INSTRING is particularly useful in situations where you want to hold the validation string in a single field, instead of needing multiple comparison values as INLIST requires.

>Thanks Rick,
>
>Will this function work if it is possible for some of my words in the comparison string to be of different lengths?
>
>Paul
>
>>As Ken and Markus have said, using SET EXACT ON will do what you need. In addition, you might find my INSTRING function useful here. INSTRING uses the length of the string being searched for to determine the comparison length. It requires only two parameters, the string being searched for and the composite string in which to search. For example, INSTRING( "ford", "THEANDAREFOR") returns .F. because the search length is four characters and the comparison string is treated as "THEA", "NDAR", and "EFOR". But INSTRING( "for", "THEANDAREFOR") returns .T. because the search length is three characters. If you're interested, you can download INSTRING from the UT files section.
>>
>>>I have noticed that inlist works as if we were doing a compare with one equal sign. IOW, it only does the compare for the length of the expressions we are checking.
>>>
>>>cTemp = "ford"
>>>inlist(upper(cTemp),"THE","AND","ARE","FOR") returns .t.
>>>
>>>I would like to use the inlist function because I think I read that it is very efficient, but I only want it to return .t. if the exact match is found.
>>>
>>>Is my only option to do something like
>>>
>>>upper(cTemp) $ "THE|AND|ARE|FOR"
>>>
>>>I see that this works but I have a routine that can run this comparison a few million times so performance is a huge concern or consideratioin.
>>>
>>>Thanks in Advance,
>>>Paul
Rick Borup, MCSD

recursion (rE-kur'-shun) n.
  see recursion.
Previous
Reply
Map
View

Click here to load this message in the networking platform