How do I search an array's values for partial match?

0 favourites
  • 4 posts
From the Asset Store
Searching
$16 USD
Searching is a game where you are challenged to find all the images with the requested letter in 30 seconds.
  • Is there a way to do this?

    Like say I need to search for all indexes that have a value that is a string, but I only want to search for part of the string.

    Example:

    I've pushed the following values to the array:

    "Oranges 2"

    "Oranges 3"

    "Grapes 2"

    "Oranges 10"

    "Oranges 10" is a value I want to keep in there, so I want to use IndexOf with Delete to kill the other two. I can't just pop the front of the array because that would get rid of "Grapes 2" as well. How would I target just the "Oranges 2" and "Oranges 3" values for deletion if I want to do it by searching for "Oranges"? Is there a better way of doing this that I'm missing?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • If you know the word to search, like you say "Oranges" then you can use len("Oranges") to count the letters in the word you are looking for. Then you can trim each word in a search loop of the Array by using left(text, count), so that you only get the word you are looking for.

  • Hi, thanks for the reply. Can you explain what you mean by "trim each word in a search loop of the array"? I understand the purpose of left and len, but I'm not sure how I would use them in an actual loop.

    Would it be like

    For "x" from 0 to array.Width

    array | Value at loopindex("x") = left(array.At(loopindex("x"), 7)

  • Yeah, thats what i mean....

    if your word is "Oranges" then you ask len("Oranges") and it will give you the answer of 7. Then you use 7 as the left() number as you did in the above case.

    So you could set::::: array | Value at loopindex("x") = left(array.At(loopindex("x"), len("Oranges"))

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)