Using LOOKDOWN with multiple search ?


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2010
    Posts
    3

    Default Using LOOKDOWN with multiple search ?

    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.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    and the list is comming from?
    1. Mars
    2. Incoming Serial data
    3. My wifey grocery
    4. Outer space via brain wave
    5. 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.

  3. #3
    Join Date
    Dec 2010
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    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?

    Too bad:

    Quote Originally Posted by electrosys View Post
    The origin of the list (string if you prefer), isn't important. Other methods of searching a string are likewise not being sought.
    http://www.scalerobotics.com

  6. #6
    Join Date
    Sep 2009
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    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"

  7. #7
    Join Date
    Dec 2010
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scalerobotics View Post
    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?

    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" ?
    Last edited by electrosys; - 10th January 2011 at 14:17.

  8. #8
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by electrosys View Post
    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/show...5028#post85028

    http://www.picbasic.co.uk/forum/show...8422#post88422
    http://www.scalerobotics.com

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts