How do I break a string from textbox into array with words/sentence constituents?

  • I know that in javascript it is possible to have a string and then put it into an array:

    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="utf-8">

    <title>Break a string and convert it into an array of words.</title>

    </head>

    <body>

    <script>

    var str = "there is a cat with a lack of dog in the attic";

    var words = str.split(" ", 10);

    for (i=0; i<words.length; i++){

    console.log(words);

    }

    </script>

    </body>

    </html>

    I know how to get input from a text box, but I do not know how to break the string from that input into array.

    I would like to be able to do the same as the code above, preferably rbe able to set a limit as well, in my example, it is 10.

    In the end I would like to store each sentence as a different array, so I imagine I will have one array

    and I would be filling it with arrays deriving from strings coming from the input.

    How can I achieve all that, perhaps i might be able to figure out storing these arrays but i am already blocked, because i do not know how to convert a string into array in the first place, just like described above, but in construct.

    Thank you in advance!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can try this:

    The TextArea is my debug, it will display all values in array

  • Thank you, it appears to work!

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