piapia123
en

Line Length Filter

Text

Everything runs locally in your browser — nothing is uploaded

Input
Drop a file here to load its contents
Output

Keep or drop lines by how long they are. The hard part is not the filtering, it is which ruler you measure with — the same line of two Latin letters and two CJK characters is 4 characters, 8 bytes and 6 columns wide, depending on the measure: · Characters — what a reader would count (by grapheme cluster, so an emoji is one) · Bytes — what the text occupies as UTF-8, which is what database columns and API limits use (a CJK character is three bytes) · Display width — typographic width, where CJK characters take two columns; this is what fixed-width checks such as phone numbers rely on Pick the wrong measure and the filter looks reasonable while keeping the wrong lines, with no error shown. So the measure is an explicit choice. The width table is the same one the page’s meta description uses, so the two can never disagree about how wide something is. Keep and Drop are a pair, not two tools: half of all users want “keep the 5 to 20 character ones” and the other half want “delete anything over 20”. One range, two directions, both expressible.

Features

  • Three measures: characters, UTF-8 bytes and display width
  • Both bounds are inclusive, and an upper bound of 0 means no limit
  • Keep and Drop share the same range
  • Bytes are counted with TextEncoder, so emoji (four bytes) and extension-block characters are handled correctly
  • The width table is shared with the meta description, so the two never drift apart
  • Filtering never alters the lines that survive: no trimming, no collapsing, no touching line endings
  • A lower bound above the upper bound raises an error rather than returning nothing
  • Everything runs locally in your browser; nothing is uploaded

How to use

  1. Paste the text you want to filter
  2. Choose the measure: characters, bytes or display width
  3. Set the bounds and pick Keep or Drop
  4. The result updates as you type; click Copy to take it

FAQ

How do the three measures differ?
Take a line of two Latin letters followed by two CJK characters: 4 characters (four grapheme clusters), 8 bytes (two CJK characters at three bytes each plus two letters at one byte) and 6 columns wide (two CJK characters at two columns each plus two letters at one). Use bytes when a database column or API has a length limit, display width when the limit is about how it looks on screen, and characters when you mean how many characters there are.
What does an upper bound of 0 mean?
0 means no limit. The input has no empty state, so a number has to act as the sentinel, and 0 is the only value that could not be a real upper bound — no line has a negative length. Note that setting both bounds to 0 removes every condition: Keep passes everything through, and Drop removes everything.
Why not just use the character count instead of display width?
Because a CJK character is about twice as wide as a Latin one. A headline of 20 Chinese characters and one of 20 Latin letters have the same character count but roughly double the typographic width — so “no more than 20 characters” overshoots a design badly in Chinese. When what you mean is how wide it looks, measure display width.

Related tools