Skip to main content
Participant
March 15, 2023
Question

Counting characters in a line leads to error when empty

  • March 15, 2023
  • 0 replies
  • 95 views

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

This topic has been closed for replies.