ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Exclude last word from a sentence.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Dario De Angelis
Exclude last word from a sentence.
on May 30, 2019 at 2:37:06 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.


Return to posts index

James Ronan
Re: Exclude last word from a sentence.
on May 30, 2019 at 3:13:23 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.


Return to posts index

Dario De Angelis
Re: Exclude last word from a sentence.
on May 30, 2019 at 5:23:24 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?


Return to posts index


Miguel de Mendoza
Re: Exclude last word from a sentence.
on May 30, 2019 at 3:30:47 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"


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]