Javascript split names

Participant ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

Hi All,
Is it possible to split the file name and get the outputs shown below.  

 

140357-XXXX_r1414_WP-book8_994x1163_CMYK_v2

output: 140357-XXXX

 

140357-XXXX-141863_r1414_AS2-BRAND-WALL-GPF2_3000x1285_CMYK_v2

output: 140357-XXXX

 

140357_r1414_WP-book8_994x1163_CMYK__XXXX_v2

output: 140357-XXXX

 

141863_r1414_AS2-TEST-BOOK-GPF2_3000x1285_CMYK_140357__XXXX_v2

output: 140357-XXXX

TOPICS
Scripting

Views

41

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Aug 26, 2021 Aug 26, 2021
Sure. String.split(separator) returns an array of strings broken up by the separator, excluding the separator. Your first example is:  var ns = myDoc.name.split("-"); ns = ns[0] + "-" + ns[1].split("_")[0]; Your second example is:  var ns = myDoc.name.split("-"); ns = ns[0] + "-" + ns[1]; Third example is: var ns = myDoc.name.split("_"); ns = ns[0] + "-" + ns[6]; //double underscore is split twice, with first instance of split being an empty string Fourth example is: var ns = myDoc.name....

Likes

Translate

Translate
Adobe Community Professional ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

LATEST

Sure. String.split(separator) returns an array of strings broken up by the separator, excluding the separator.

 

Your first example is: 

var ns = myDoc.name.split("-");

ns = ns[0] + "-" + ns[1].split("_")[0];

 

Your second example is: 

var ns = myDoc.name.split("-");

ns = ns[0] + "-" + ns[1];

 

Third example is:

var ns = myDoc.name.split("_");

ns = ns[0] + "-" + ns[6]; //double underscore is split twice, with first instance of split being an empty string

 

Fourth example is:

var ns = myDoc.name.split("_");

ns = ns[5] + "-" + ns[7]; //double underscore is split twice, with first instance of split being an empty string

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines