How do I check, if string contains another string?

0 favourites
  • 5 posts
  • Hello everyone, simple question:

    I have a string variable, let's call it "My name is Peter". I am going to store this variable in an array at some random XYZ place.

    Now I want to check whether the whole array contains the string "Peter". I haven't found any solution to this.

    Any ideas? maybe I need a plugin?

  • Contains value

    Searches the entire array to check if any of the elements contains the given value. For example, you can use this to test if the string "sword" is stored anywhere in the array.

  • Yes, but if the string in the array is 'I have a sword', I won't find it by checking every element for the string 'sword', as it has to be a perfect match.

    I guess the expression 'regex' is exactly what I need. I'll try it out.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Local variable 'check' = 0

    Iterate the array with 'For each element'.

    Compare two values ... find(Array.CurValue,"sword") not = - 1

    If that condition is true then the expressions Array.CurX, Array.CurY and Array.CurZ contain the position in the array.

    And CurValue contains the string

    Optional you can stop the iteration with the action stop loop at this point

    If you want to know all occurrences, then you need an array to hold the positions.

  • Works. Thanks!

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