Browse the docs

lines

Counts the lines in some text.

Keyboard Maestro: LINES

Details #

lines(text) takes exactly one argument and returns how many lines it holds. Empty text is 0 lines, and text with no line break is 1. Every line break adds a line, empty lines included. A number, true/false or list is turned into text first (see string).

Parameters #

Takes 1 argument. {{ lines(text) }}

Examples #

lines("first\nsecond\nthird")
→ 3
lines(text)
→ 3
Sample variableValue
texta b

Gotchas #

  • Calling it with no argument or two arguments is an error: lines() takes 1 argument, got 2.

  • A line break at the very end counts a final empty line: lines("a\nb\n") is 3.

  • To get the lines themselves, use split with a line break.