• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Javascript split names

Contributor ,
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

314

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

Community Expert , 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.

...

Votes

Translate

Translate
Community Expert ,
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

Votes

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