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.
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.
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
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
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 ?
Last edited by electrosys; - 8th January 2011 at 20:01. Reason: Example added
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.
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:
Code: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"
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" ?
Last edited by electrosys; - 10th January 2011 at 14:17.
Sorry electrosys, I said "too bad" because withyou 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...}],VarOther methods of searching a string are likewise not being sought.
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/show...5028#post85028
http://www.picbasic.co.uk/forum/show...8422#post88422
http://www.scalerobotics.com
Bookmarks