Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Exclude last word from a sentence.

  • Exclude last word from a sentence.

    Posted by Dario De angelis on May 30, 2019 at 2:37 pm

    Hi guys, I’m working on a sport template based on .csv files.

    In the .csv’s file I have many player’s names in “SURNAME NAME” format that I need to transform in (at least) SURNAME format (even better would be the SURNAME N. format)

    I’ve tried the following expression:

    text_array1 = thisComp.layer("\\FILENAME.csv")("Data")("Outline")("\\PLAYER")("\\PLAYER0").toUpperCase().split(" ");
    try
    {
    text_array1[1]+" "+ text_array1[2];
    }
    catch(e) { text_array1[0]; }

    that it’s the reverse of what I want (it takes only the first word of the sentence) but, anyways, it works well with one word surnames.

    The issue is with the double word surnames when the expression only give me the first part of surname (ex. SUR SURNAME only give me SUR) , so I’m asking myself if there is a way to reach the final result I want.

    Dario De angelis replied 6 years, 11 months ago 3 Members · 3 Replies
  • 3 Replies
  • James Ronan

    May 30, 2019 at 3:13 pm

    Hey Dario

    How about this:


    text_array1 = thisComp.layer("\\FILENAME.csv")("Data")("Outline")("\\PLAYER")("\\PLAYER0").toUpperCase().split(" ");
    firstInitial = text_array1[text_array1.length-1].split("")[0];
    if (text_array1.length > 2){
    text_array1[0] + " " + text_array1[1] + " " + firstInitial;
    } else if (text_array1.length == 2) {
    text_array1[0] + " " + firstInitial;
    } else {
    text_array1[0];
    };

    It assumes that a surname will never be more than 2 words.

  • Miguel De mendoza

    May 30, 2019 at 3:30 pm

    To get the las item of the array you can get it like this:

    var myArray = ["SKY", "WALKER", "ANAKIN"];
    var lastItem = myArray[myArray.length -1]; // returns "ANAKIN"
    var nameInitial = lastItem[0]; //returns "A"

  • Dario De angelis

    May 30, 2019 at 5:23 pm

    Works well.

    Only as a learn purpose, it is an if/else expression with 3 variables:
    – More than 2 word name: use the 1st and the 2nd words
    – 2 word name: use only 1st
    – 1 word name: use it

    Right?

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