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

INDD: Check if LayerName contains specific Char

Explorer ,
Feb 09, 2022 Feb 09, 2022

Hello guys

 

I was wondering how to check if a specific char is contained in the layer name.
Tried .contains("_") and .include("_") but neither worked...

 

Does anyone know the Answer to this question?

 

Thanks a lot

TOPICS
Scripting
603
Translate
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

Participant , Feb 09, 2022 Feb 09, 2022

Hey, try with indexOf:

'My_Layer'.indexOf('_') > -1; // returns true
'MyLayer'.indexOf('_') > -1; // returns false

 

Translate
Participant ,
Feb 09, 2022 Feb 09, 2022

Hey, try with indexOf:

'My_Layer'.indexOf('_') > -1; // returns true
'MyLayer'.indexOf('_') > -1; // returns false

 

____________________
Robotic Process Automation in Desktop Publishing (Book): https://doi.org/10.1007/978-3-658-39375-5
Translate
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
Explorer ,
Feb 09, 2022 Feb 09, 2022

@GNDGN  You're the Man 🙂

 

I forgott about .indexOf... ups

 

Thanks for your extremely fast reply!

 

Translate
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
Advocate ,
Feb 12, 2022 Feb 12, 2022

Or may be you can try match:

'My_Layer'.match('_') != null

Best

Sunil

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

.match() uses a regular expression (even if your example contains a literal), and creates an array -- which is expensive. If you have to use a regular expression to test whether a string contains a substring, .test() is quicker because it doesn't create an array, it returns a boolean.

P.

Translate
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
Advocate ,
Feb 15, 2022 Feb 15, 2022
LATEST

Thank you for explaining, .test() is also new for me.

Translate
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