Search for Text within a Cell

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • I feel like this should be simply but I've been staring at my Event Editor for ages and my mind's starting to blank out.

    Basically, I have an Edit Box object which the user can type words into. When a word is input and the user presses "Enter", a fastloop begins which searches for the input word within a specific column of a DataGrid object and then returns the text contained within the adjacent column. This has been tried and tested and works perfectly fine.

    My problem is that, for the sake of efficiency and to cut out a lot of monotonous work, I'd like the fastloop search to search for text within the cell, rather than look for a cell with an exact match of the input text.

    For example, currently the user types in "hello" and the fastloop searches for a cell within column 2 which contains exactly the text "hello". I'd like the user to search "hello" and the loop to find the text "hello" within a cell that contains the text "hello; hi; hey".


    My current, very basic, formula:

    Code
    + Upon pressing "Enter"
    - Special: Start loop "search" NLines("DataGrid") times
    
    
    + On loop "search"
    + Alterable String A of Edit Box = Text$("DataGrid", LoopIndex("search"), 2)
    - Rich Edit Object: Append 'Alterable String A("Edit Box") + NewLine$' to text
    - Rich Edit Object: Append 'Text$("DataGrid", LoopIndex("search"), 3) + NewLine$ + NewLine$' to text

    Sorry if none of this makes any sense, I'm very tired :)

  • You can use "find" builtin function:

    Find(Text$("DataGrid", LoopIndex("search"), 2), "hello", 0 ) >= 0

    would mean "hello" is found

    while = -1 means that the substring is not found

    Code
    + Upon pressing "Enter"
    - Special: Start loop "search" NLines("DataGrid") times 
    
    
    + On loop "search"
    + (compare two general values) Find(Text$("DataGrid", LoopIndex("search"), 2), "hello", 0 ) >= 0
    - Rich Edit Object: Append 'Alterable String A("Edit Box") + NewLine$' to text
    - Rich Edit Object: Append 'Text$("DataGrid", LoopIndex("search"), 3) + NewLine$ + NewLine$' to text

    a selection of my Fusion examples can be found Please login to see this link.

  • Wowo, I could cry, thank you!

    I was on the right lines with the find function I was just trying to find a stupid way of inputting it, like an idiot, rather than using the "Compare two general values" event...

  • One little issue I'm now having: the player could potentially input "ell" or "e" and this would result in the same outcome as inputting "hello". I can slightly remedy this by amending the "Enter string to look for" by adding '+";"' but the player can still input the the ending of any words and get the same outcome (e.g. "ello" or "o").

    I need to make it so that the full word must be found, not just a segment of the word, is there a function for this?

  • Use

    Code
    + (compare two general values) Find(" "+Text$("DataGrid", LoopIndex("search"), 2), " "+<FINDING TEXT HERE>+";", 0 ) >= 0


    should *technically* work.
    Or, you can use the text tokenizer, tokenise the DataGrid Text with by an action ; and compare the word you want to find with the element

    - BartekB

    Join the Click Converse Discord! - Please login to see this link.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!