Behavior Control
This control is developed by:
AvatarDJ Sures
Created December 29 2018
Updated December 29 2018
Help Index

Getlinecontainingfromarray

How To Download and Use This Control

  1. Make sure you have the latest version of EZ-Builder installed.
  2. Select Download This Control button below to download the file.
  3. Double click the downloaded file to open it.
  4. The installer will automatically add this control to EZ-Builder.
Download This Control

Adds a new EZ-Script function GetLineContainingFromArray() that will return an item from the array that contains the specified text. The syntax of the function is...

Code:


GetLineContainingFromArray("$array", "Txt to search for")


An example is as such...

Code:


# Fill an array with the word "Banana" 20 times
defineArray($array, 20, "Banana")

# set the 5th index to these words
$array[5] = "Apple face"

# get the first line containing the text "apple"
$x = GetLineContainingFromArray("$array", "apple")

print("Found: " + $x + " Among the bananas")


Source Code

You can download the source code here: GetLineContainingFromArray.zip



DJ Sures
Synthiam
December 29 2018
Have you tried loading each line into an array? That way you can simply loop through the array rather than looping through the file. 

Reading from a file that way is indeed slow - as you’re not noticing:). Memory is much faster. Much much faster
December 29 2018 — Updated December 29 2018
Thanks DJ! I gave it a try and I think I must be doing something wrong, because according to the output timestamp, reading from an array isn't always faster than reading from the file. Here is my code (*note, "$dictionary_a" is an array containing 7236 strings, which I created in a different script):

$lookUpIndex=0
$target="axe"
$len=Length($target)

:loop
IF (contains($dictionary_a[$lookUpIndex],$target))
  $line=$dictionary_a[$lookUpIndex]
  $match=split($line, " ",0)
ELSE
  $lookUpIndex++
ENDIF
IF (Length($match)=Length($target))
  print("On line " +$lookUpIndex +", line reads: "+$line)
  halt()
ENDIF
IF ($lookUpIndex<7236)
  goto(loop)
ELSE
  print("Not in dictionary")
  halt()
ENDIF

_______________________________________
Timestamp for reading from array    (00:00:02.4314810)
Timestamp for reading from text file (00:00:01.7622398)

I know I must be doing something very inefficient, just not sure what!:)

DJ Sures
Synthiam
December 29 2018
Here, try this pluginhttps://synthiam.com/Software/Manual/GetLineContainingFromArray-17382

Put all your data in the array and rock that function. The source code is available for the plugin if you need to modify it
December 29 2018 — Updated January 4
**UPDATE,**

So this plugin really is a game changer for searching vast amounts of info stored in arrays. I reorganized the entire dictionary to rank order from shortest character length strings to longest, and alphabetically as a second order rank. Now when I use the search function, i immediately get the result i want from the array, and i don't need to do any matching or verification, which speeds it up even more. I initially ran into an issue where a shorter word like "space" was contained in a longer word, like "aerospace", but rank ordering the input solved that issue. My execution time went from ~1.5s for short strings "8 words", to 0.16s!!! Immense difference. Now the votrax is by far the slowest part of the system (as it should be).

@DJ Sures, you have created a fantastic product that continues to impress me the more I use it!! Thank you!!!
DJ Sures
Synthiam
January 4
Hey GBot, thanks for the kind words! I'm really glad this plugin is working for you - and access to the source code means you can make any necessary changes to it:D