PDA

View Full Version : Using LOOKDOWN with multiple search ?



electrosys
- 8th January 2011, 18:01
Is there a way that LOOKDOWN can be used to return the position of multiple instances of the same search term within a list ? The sort of situation I had in mind is identifying the positions of field separators - commas, spaces etc.

Thanks.

mister_e
- 8th January 2011, 18:12
and the list is comming from?


Mars
Incoming Serial data
My wifey grocery
Outer space via brain wave
User entry


Usually an home made parser can do magic, but I'm not sure it is easy to implement for item 1,3,4 above ;)

electrosys
- 8th January 2011, 19:31
The origin of the list (string if you prefer), isn't important. Other methods of searching a string are likewise not being sought.

My question is specific to the LOOKDOWN command: I am seeking to establish the usefulness (or otherwise) of this somewhat unique command. Is LOOKDOWN capable of returning more than just the position of one instance of a character, when that character may feature more than once within a string (or list of characters) ?

Maybe an example would clarify my question.
Suppose I have a string "mississippi", and search that string for the character 'i' using LOOKDOWN. Which 'i' position will LOOKDOWN return ? (The first, or the last - the manual doesn't say) Then, is there a way that LOOKDOWN can be 'coerced' into returning the position of all four 'i' s ?

Bruce
- 9th January 2011, 19:49
With "mississippi" in the constant list, and "i" as the search value, LOOKDOWN will return a value of 1. m = 0, i = 1 in the list.

There's no way that I know of to make it continue on once the first instance of the search value has been found in the list of constants.

ScaleRobotics
- 9th January 2011, 21:39
Seems kind of futile, searching for characters in a known constant that is already pre-programmed into the chip. Shouldn't you already know where they are? :D

Too bad:


The origin of the list (string if you prefer), isn't important. Other methods of searching a string are likewise not being sought.
:(

vaporized
- 10th January 2011, 00:17
Hello.

Suppose you're collecting data in an array called buffer and it contains "mississippi".
To find at which positions within the array there is an "i" you can use another array, e.g. search_result, and store those positions in it.

Something like this:




search_item="i"
cnt=0
for n=0 to 10
if buffer[n]=search_item then search_result[cnt]=n
cnt=cnt+1
next n




If you'd look, say, for an "s" then you could replace
search_item="i"
with
search_item="s"

electrosys
- 10th January 2011, 14:14
Seems kind of futile, searching for characters in a known constant that is already pre-programmed into the chip. Shouldn't you already know where they are? :D

Too bad:

:(

You are making an assumption that the list of constants is known.
I only used the example of "mississippi" as I was unable (by definition) to give the contents of an unknown $tring as an example. It seems that LOOKDOWN, although useful for conversion to decimal, is unsuitable for scanning a string (list) of uncertain contents, where duplication may occur - as would happen with field separators. (Thanks, Bruce).
I don't see any futility.

Why do you say "Too bad" ?

ScaleRobotics
- 10th January 2011, 15:23
You are making an assumption that the list of constants is known.


Sorry electrosys, I said "too bad" because with
Other methods of searching a string are likewise not being sought. you seem pretty reluctant to use anything other than lookdown. I assume you are looking up constants .... well, because that is what lookdown does. From the manual "LOOKDOWN Search,[Constant{, Constant...}],Var

The reason you were asked where this list comes from, was to see what you were using it for, to see if you really wanted to use Lookdown, or if there were other alternatives that might work better for you.

If you have PBP ver 2.60 arrayread is very nice. Here are a couple examples of how it can be used to parse strings.

http://www.picbasic.co.uk/forum/showthread.php?t=12727&p=85028#post85028

http://www.picbasic.co.uk/forum/showthread.php?t=5387&p=88422#post88422