search text within text

0 favourites
  • 4 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • Hi, I have a sentence in a text object ,i want to check if the sentence has a certain word in it. im pretty sure I need to use tokenat but don't understand it could anyone help explain it simply with an example


    I went to the shops and bought coffee,tea,cakes and biscuits.

    I would like to see if the sentence has the word tea in it


  • In this case I don't think you need tokenat, just find()

    find(sentence, "tea") will return the index of the first time it finds "tea" and -1 if it doesn't find it at all.

    If you just wanted an event to check if it existed or not, you could do System-> Compare two values.The first value would be find(sentence, "tea"), then check if it is NOT equal to -1. The event will fire if the text is found.

    EDIT: Note, you have to be careful with this, because let's say you had the word "team" in your sentence. It would find "tea" and then return that it found something.

  • Just to follow up, tokenat() is used if you want to break up a string that is delineated by a common character. So for example, if you had a string that was like "coffee,tea,cakes,biscuits," that is delineated by commas.

    If you wanted to get, say, the third item in that list, you would do tokenat(list, 2, ","). That says "get me the third (remember indexing is 0-based, so it's 2 and not 3) object in the given string where the objects (or tokens) are separated by a comma"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks very much Wertle, I used find and works fine also understand the tokenat too, much appreciated :)

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