Probably a silly question about 'find'

Ken Ray kray at sonsothunder.com
Thu Jan 18 11:25:42 EST 2007


On Jan 18, 2007, at 9:48 AM, Devin Asay wrote:

> On Jan 18, 2007, at 2:32 AM, Peter Alcibiades wrote:
>
>> Feels like a very silly question, but it is stumping me.
>>
>> How do I use 'find' to find '4' when it occurs by itself but not 4  
>> when it
>> occurs in '4.1', when searching the contents of a field?
>>
>> I have a field with tab separated values in the form
>>
>> 1	1234
>> 2	2.56
>> 3	4.1
>> 4	9.274
>>
>> and I want to find only that line in which there is a match of the  
>> inputted
>> string with the first item.  The first item will always be a  
>> unique value.
>> So I want in some way to do a find on 4 that will pick up only  
>> line 4, and
>> not the occurrence of 4 in line 3.
>>
>> Find word doesn't seem to work, because presumably Rev sees the  
>> '.' as a word
>> limiter.  Whereas in fact, its a decimal....  Find string in item  
>> 1 doesn't
>> work either.   In fact, none of the parameters on find seem to work.
>
> Peter,
>
> Find is probably not the best choice in this case. I would use the  
> lineOffset function and look for 4 & tab, like this:
>
> put lineOffset(4 & tab,fld "thevalues") into tLineFound

And I would add to that to precede the number to search for with a CR  
just to be on the safe side:

   put lineOffset(CR & 4 & tab,CR & fld "thevalues") into tLineFound

This way, suppose you had a series of values where some lines may be  
skipped and you want to know if a line *was* skipped; something like:

1	1234
2	2.56
3	4.1
9	8.35
14	9.274
18	20.121

WIthout the "CR" in there, you would match the line starting with 14  
if you just looked for ("4" & tab), but you wouldn't match it if you  
look for (CR & "4" & tab). Note that it is very important that you  
include the preceding CR with the list to find as well, otherwise  
your lineoffset will be off. So it can't be:

   lineOffset(CR & 4 & tab,fld "thevalues")

but must be

   lineOffset(CR & 4 & tab,CR & fld "thevalues")

HTH,

Ken Ray
Sons of Thunder Software, Inc.
Web Site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com






More information about the use-livecode mailing list