FIND Question
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
FIND Question
I'm attempting to search an array 290 lines with 15 items on each line to retrieve data specific to a file name.
The fileName is item 3 on each line.
Problem is - some have similar names...
for example there are four different lines of data each for;
30Pel.jpg
130Pel.jpg
230Pel.jpg
330Pel.jpg
130Pel.jpg works, as do the 230Pel.jpg and 330Pel.jpg searches
However when I use;
Find String 30.jpg... sometimes I get the line I want and sometimes it chooses one of the other 3 lines and provides incorrect data when I retrieve values from the foundLine.
--======= here's my code=========
find string img2Display in fld "ImageData" --FIND; string, whole, words all see problematic
put the value of the foundLine into tData
--====================
any advice appreciated
Cheers!
The fileName is item 3 on each line.
Problem is - some have similar names...
for example there are four different lines of data each for;
30Pel.jpg
130Pel.jpg
230Pel.jpg
330Pel.jpg
130Pel.jpg works, as do the 230Pel.jpg and 330Pel.jpg searches
However when I use;
Find String 30.jpg... sometimes I get the line I want and sometimes it chooses one of the other 3 lines and provides incorrect data when I retrieve values from the foundLine.
--======= here's my code=========
find string img2Display in fld "ImageData" --FIND; string, whole, words all see problematic
put the value of the foundLine into tData
--====================
any advice appreciated
Cheers!
-
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: FIND Question
Hi.
You mentioned "array", but do you in fact just have, er, an "array" of data? In other words, not an array variable?
Can you use the "find whole"? One reason I mention this is that the "find String" variant is powerful, but also non-discriminatory. It does not use the first char as a baseline, a useful parsing gadget. Look up the handful of "find" variants in the dictionary, if you already have not, and see if one better fits your data set. But this may not always hold if the data set changes, breaking the find limitations.
Otherwise, if the structure of your data makes any of the out-of-the-box finds dicey, you may have to index the data in some unique way. I have added all sorts of indexing strings to lists in order to be able to manage them. The added string can be deleted as needed, but is there to sort, extract or find. Something like:
1000^30Pel.jpg
1001^130Pel.jpg
1002^230Pel.jpg
1003^330Pel.jpg
Here the "^" char can be an itemDelimiter to be able to separate the real data from the composite.
Or you can place all your data in an array variable, and in essence do the same thing. The keys of the array form that additional "parsing" level of control.
Something like that.
Craig Newman
You mentioned "array", but do you in fact just have, er, an "array" of data? In other words, not an array variable?
Can you use the "find whole"? One reason I mention this is that the "find String" variant is powerful, but also non-discriminatory. It does not use the first char as a baseline, a useful parsing gadget. Look up the handful of "find" variants in the dictionary, if you already have not, and see if one better fits your data set. But this may not always hold if the data set changes, breaking the find limitations.
Otherwise, if the structure of your data makes any of the out-of-the-box finds dicey, you may have to index the data in some unique way. I have added all sorts of indexing strings to lists in order to be able to manage them. The added string can be deleted as needed, but is there to sort, extract or find. Something like:
1000^30Pel.jpg
1001^130Pel.jpg
1002^230Pel.jpg
1003^330Pel.jpg
Here the "^" char can be an itemDelimiter to be able to separate the real data from the composite.
Or you can place all your data in an array variable, and in essence do the same thing. The keys of the array form that additional "parsing" level of control.
Something like that.
Craig Newman
Re: FIND Question
Thanks Craig,
The "array" is simply lines of comma-delimited text sitting in a locked and hidden field.
Here are three lines from it...
Img,0,30Pel.jpg,623,418,662,480,642,449,39,62,644,471,,
Img,0,30LLeg.jpg,612,627,658,718,635,672,46,91,642,640,642,708
Img,0,30ULeg.jpg,630,627,658,735,644,681,28,108,641,639,641,708
Find whole doesn't find anything at all...
Find string - I believe will bring the same result even if I use your renaming format with the carrots. BUT that is an interesting suggestion and I may find that useful!
If it possible to use TWO items ***WITH*** the comma between them in a search string?
If I used Find "0,30Pel.jpg" it would solve the problem - but I'm not sure how to code that...
You mentioned "array", but do you in fact just have, er, an "array" of data? In other words, not an array variable?
Can you use the "find whole"? One reason I mention this is that the "find String" variant is powerful, but also non-discriminatory. It does not use the first char as a baseline, a useful parsing gadget. Look up the handful of "find" variants in the dictionary, if you already have not, and see if one better fits your data set. But this may not always hold if the data set changes, breaking the find limitations.
Otherwise, if the structure of your data makes any of the out-of-the-box finds dicey, you may have to index the data in some unique way. I have added all sorts of indexing strings to lists in order to be able to manage them. The added string can be deleted as needed, but is there to sort, extract or find. Something like:
1000^30Pel.jpg
1001^130Pel.jpg
1002^230Pel.jpg
1003^330Pel.jpg
Here the "^" char can be an itemDelimiter to be able to separate the real data from the composite.
Or you can place all your data in an array variable, and in essence do the same thing. The keys of the array form that additional "parsing" level of control.
Something like that.
Craig Newman
The "array" is simply lines of comma-delimited text sitting in a locked and hidden field.
Here are three lines from it...
Img,0,30Pel.jpg,623,418,662,480,642,449,39,62,644,471,,
Img,0,30LLeg.jpg,612,627,658,718,635,672,46,91,642,640,642,708
Img,0,30ULeg.jpg,630,627,658,735,644,681,28,108,641,639,641,708
Find whole doesn't find anything at all...
Find string - I believe will bring the same result even if I use your renaming format with the carrots. BUT that is an interesting suggestion and I may find that useful!
If it possible to use TWO items ***WITH*** the comma between them in a search string?
If I used Find "0,30Pel.jpg" it would solve the problem - but I'm not sure how to code that...
You mentioned "array", but do you in fact just have, er, an "array" of data? In other words, not an array variable?
Can you use the "find whole"? One reason I mention this is that the "find String" variant is powerful, but also non-discriminatory. It does not use the first char as a baseline, a useful parsing gadget. Look up the handful of "find" variants in the dictionary, if you already have not, and see if one better fits your data set. But this may not always hold if the data set changes, breaking the find limitations.
Otherwise, if the structure of your data makes any of the out-of-the-box finds dicey, you may have to index the data in some unique way. I have added all sorts of indexing strings to lists in order to be able to manage them. The added string can be deleted as needed, but is there to sort, extract or find. Something like:
1000^30Pel.jpg
1001^130Pel.jpg
1002^230Pel.jpg
1003^330Pel.jpg
Here the "^" char can be an itemDelimiter to be able to separate the real data from the composite.
Or you can place all your data in an array variable, and in essence do the same thing. The keys of the array form that additional "parsing" level of control.
Something like that.
Craig Newman
Re: FIND Question
Hi Steve,
Best
Klaus
I would use ITEMOFFSET in a "repeat for each" loop, something like this:sbonham wrote:The "array" is simply lines of comma-delimited text sitting in a locked and hidden field.
Here are three lines from it...
Img,0,30Pel.jpg,623,418,662,480,642,449,39,62,644,471,,
Img,0,30LLeg.jpg,612,627,658,718,635,672,46,91,642,640,642,708
Img,0,30ULeg.jpg,630,627,658,735,644,681,28,108,641,639,641,708
Find whole doesn't find anything at all...
Find string - I believe will bring the same result even if I use your renaming format with the carrots. BUT that is an interesting suggestion and I may find that useful!
If it possible to use TWO items ***WITH*** the comma between them in a search string?
If I used Find "0,30Pel.jpg" it would solve the problem - but I'm not sure how to code that...
Code: Select all
...
## Or create a function or handler and pass this as a parameter
put "30Pel.jpg" into String_to_Find
set the WHOLEMATCHES to TRUE ##!
repeat for each line tLine in your_list
put itemoffset(String_to_Find,tLineI) into found_it
if found_it = 0 then
next repeat
end if
## Now do something with that line contained in tLine.
## You get the picture :-)
end repeat
...
Klaus
Re: FIND Question
Hi,sbonham wrote: Here are three lines from it...
Img,0,30Pel.jpg,623,418,662,480,642,449,39,62,644,471,,
Img,0,30LLeg.jpg,612,627,658,718,635,672,46,91,642,640,642,708
Img,0,30ULeg.jpg,630,627,658,735,644,681,28,108,641,639,641,708
If it possible to use TWO items ***WITH*** the comma between them in a search string?
If I used Find "0,30Pel.jpg" it would solve the problem - but I'm not sure how to code that...
Another way to do it...
Considering that myCSV contains the 3 lines above, then
you can use the filter command with a simple regular expression.
You can try this very quick test:
Code: Select all
put "30Pel.jpg" into mySearch
filter myCSV with regex pattern comma & mySearch & comma
put myCSV
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: FIND Question
Thanks Klaus and Thierry,
Thierry's suggestion to include a comma in the string was beautifully simple!
This worked;
find string comma & image2Display in fld "ImageData" --FIND; string, whole, words
put the value of the foundLine into tData
--- extract items as needed
I did not realize it was possible to include punctuation in a string! Easy!!
All the best!
Thierry's suggestion to include a comma in the string was beautifully simple!
This worked;
find string comma & image2Display in fld "ImageData" --FIND; string, whole, words
put the value of the foundLine into tData
--- extract items as needed
I did not realize it was possible to include punctuation in a string! Easy!!
All the best!