How do I find a string in array, then insert a string before and string after?

0 favourites
  • 3 posts
From the Asset Store
This collection of music is the beautiful performance of rather small strings ensemble (8 first violins, 6 second violin
  • I have a variable named gFindWord = dog

    So the initial text would look something like: mouse rabbit dog elephant

    The text is separated into an array. I want to find the word dog and then insert cat before and after dog.

    The goal is after clicking the button the text would look like: mouse rabbit cat dog cat elephant

    Unfortunately, I am getting something like this: cat cat mouse rabbit dog elephant

    I added a variable called gWordX in hopes to identify the CurX and then use CurX to insert cat. Still not working. Do I even need to identify CurX? Can't I just use CurValue?

  • You can use the expression Array.IndexOf to get the index (position in array) of whatever you are trying to find.

    So if the goal is to insert values before and after the specified index, you would use the array action insert "cat" at index Array.IndexOf(gFindWord) for after, and Array.IndexOf(gFindWord)-1 for before.

    Edit: It might be +1 for after and no adjustment for before.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks oosyrag!! You reply helped me again. Much appreciated!!:)

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