ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Search and replace item in array ?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Shai Benshoshan
Search and replace item in array ?
on Mar 19, 2018 at 4:22:37 pm

Probably there is a better way to do it:
I am trying to replace all the instances of a specific font in an array :

This method is working to find "Roboto" and replace it with "Open Sans"

toSort = ["Verdana", "Roboto", "Times New Roman", "Verdana", "Roboto"];
var str = toSort.toString();
var patt1 = /Roboto/;
var result = str .replace(str.match(patt1), "Open Sans");

Whan I try to search globally (var patt1 = /Roboto/g;) it's not working at all (not finding "Roboto" at all );

My final goal is to set the search word and the replace word as array elements :
this is not successful at all for me :

Thank you for any help or idea

toSort = ["Verdana","Roboto","Times New Roman","Verdana", "Roboto"];
desFont = ["Exo2","Open Sans"];

var str = toSort.toString();
var src = toSort[0].toString();
var rplc = desFont[0].toString();

var patt1 = /src*/g;
var result = str .replace((str.match(patt1)), rplc);
alert( result);

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved