Creative Communities of the World Forums

The peer to peer support community for media production professionals.

  • Posted by Phil Largilliere on April 20, 2016 at 11:00 am

    Hi every one !

    I would like to split a line in 3 news line. I suppose that the client enter a sentence between 3 and 15 words.
    The first line contains the first word, the last line contains the last word, and the 2nd line contains all the other word…

    First, I want to replace the first and the last space (” “) by a pipe (“|”), then use the code split() but I have a problem. How can I define where is the last word (or space) ?

    Thanks for your help…

    Phil Largilliere replied 10 years, 3 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    April 20, 2016 at 1:46 pm

    Maybe lastIndexOf() is what you’re looking for:

    myText.lastIndexOf(” “);

    Dan

  • Phil Largilliere

    April 20, 2016 at 2:08 pm

    It’s a part of the solution, but I don’t know how to use it.

    I would like to know how many spaces there is in the text, or how many words, because “replace” doesn’t work with the number of characters, does it ?

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy