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

Counting characters in a line leads to error when empty

New Here ,
Mar 15, 2023 Mar 15, 2023

Copy link to clipboard

Copied

Hi there, I hope someone can give me a tip:

I'm counting the characters of a particular line in a text layer using this expression:

 

line_01_count = src.value.split(/\n|\r/); line_01_count[0].length;

line_02_count = src.value.split(/\n|\r/); line_02_count[1].length;

line_03_count = src.value.split(/\n|\r/); line_03_count[2].length;

 

This works great, but if the text layer referred to has less than three lines, the expression gives me an error. How can I fix this? Is there maybe a way to disregard a part of an expression if the value is empty to get rid of the error?

Would be glad for some help and sorry if this is a rookie question, just starting to get into expressions a bit more.

Cheers
Mathias

TOPICS
Error or problem , Expressions

Views

33

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
no replies

Have something to add?

Join the conversation