Overview
Introduction
'How many lines is this?' sounds simple, but the answer depends on whether you're counting line breaks or the lines those breaks create, and the two numbers differ by exactly one for non-empty text.
It runs entirely client-side, so nothing you paste is ever uploaded to a server.
What Is Line Counter?
A counter that reports the total number of lines in your text, splitting on any of the common line-ending styles.
It runs entirely client-side as part of this site's String Tools collection, so nothing you paste is ever uploaded to a server.
How Line Counter Works
The text is split on a regular expression matching \r\n, \r, or \n, and the resulting number of segments is the line count.
The transformation happens synchronously in JavaScript the moment you type, with no network round trip involved.
When To Use Line Counter
Use it when you need the actual line count of a document, script, or list, rather than just its newline-character count.
It's a fast way to get the answer without opening a code editor, a REPL, or writing a one-off script just to check.
Often used alongside Newline Counter and String Length Counter.
Features
Advantages
- Recognizes all three common line-ending styles consistently.
- Reports the intuitive 'number of lines' figure rather than a raw character count.
Limitations
- Doesn't distinguish which line-ending style was used, only the total line count.
- Treats a trailing blank line (text ending in a newline) as an additional counted line, matching how most editors display line numbers.
Examples
Best Practices & Notes
Best Practices
- Use Newline Counter instead if you specifically need the newline-character count rather than the line count.
Developer Notes
The implementation is `input.split(/\r\n|\r|\n/).length`, which matches \r\n as a single unit before falling back to lone \r or \n, so Windows-style line endings aren't double-counted and the result is always newline count + 1 for non-empty input.
Line Counter Use Cases
- Checking a document's or script's total line count
- Verifying a list has the expected number of entries
- Comparing line counts before and after an edit
Common Mistakes
- Confusing line count with newline count; they differ by one for non-empty text.
- Expecting empty input to report a line count of 1.
Tips
- Pair with Newline Counter for a complete picture of a document's line structure.