Remove Leading & Trailing SpacesTrim Text Line by Line

Paste text, pick Each line or Whole text, and trim spaces, tabs, and non-breaking spaces from the start and end. You can also strip bullets, quote marks, and trailing commas.

Your input is never sent anywhere.

Details
0 chars0 lines
0 chars / 0 lines0 removed
Options

Whitespace to trim

In Each line mode, line breaks separate the lines, so they are kept. Switch to Whole text to trim blank lines at the start and end.

Remove specific characters

Common marks (one tap)

Remove a set number of characters

Cleanup

Letter case

What the trim does and what it leaves alone

This tool removes whitespace and unwanted characters from the start and end of your text and leaves everything in the middle as it is. In Each line mode every line is trimmed on its own, which suits lists copied from Excel, emails, or logs. In Whole text mode only the very start and very end of the block are trimmed. You can trim just one end, remove bullets, list numbers, quote marks, or a trailing comma, cut a fixed number of characters, and check the input for non-breaking and zero-width spaces that TRIM does not remove.

Common jobs: Excel lists, quoted emails, logs

Cells that won't match in VLOOKUP

Paste the column, keep Each line selected, and check the Hidden character check for non-breaking spaces and zero-width characters. Trim, then paste the result back so lookups match.

Quoted emails and chat messages

Remove the > quote marks, bullets, or list numbers from the start of every line in one pass, and get plain text back.

Code, config files, and data exports

Use End only to strip trailing whitespace without touching indentation, or remove trailing commas and semicolons from every line.

Log lines with a fixed prefix

Cut a set number of characters from the start of each line to drop a timestamp or ID, then compare the remaining messages.

How to trim text in 4 steps

  1. Paste your text into Input, or click Load sample to see how it behaves.
  2. Choose Each line or Whole text, then choose Both ends, Start only, or End only.
  3. Turn on any extras: whitespace types, specific characters, a set number of characters, empty-line removal, or Merge repeated spaces.
  4. Click Copy result, or download the text as a .txt file.

Note: The result updates as you change anything. Use the arrow button above the result to move it back into Input and trim it again with different settings.

How the options are applied

  • Order of steps: whitespace is trimmed first, then the set number of characters is cut, then your typed characters and the one-tap marks are removed, then wrappers. Empty-line removal, Merge repeated spaces, and letter case come last.
  • Whole text mode: everything is treated as one block. Specific characters and character counts are applied once, to the start and end of the whole block, not to each line.
  • Wrappers: they are removed only when the text starts and ends with a matching pair: " ", ' ', backticks, curly quotes, ( ), [ ], { }, or < >. A line such as (a) and (b) therefore loses its outer parentheses.
  • Line endings: Windows (CRLF) and old Mac (CR) line endings are read as line breaks, and the result uses a single LF line break.
  • Empty lines: Remove empty lines also deletes lines that contain only spaces, tabs, non-breaking spaces, or zero-width spaces.

Which settings fix which problem

Find your case, then match the scope, end, and options.

ProblemSettingsResult
VLOOKUP or XLOOKUP will not matchEach line, Both ends, non-breaking spaces onHidden spaces at the edges of each cell are removed
Indented lines you want flush leftEach line, Start onlyLeading spaces and tabs removed, trailing spaces kept
Trailing spaces in code or configEach line, End onlyIndentation is untouched
Quoted email with > marksStart: Quote mark >, Repeat onThe > is removed, including nested > >
Bulleted or numbered list to plain linesStart: Bullets, List numbersMarkers removed, text kept
Trailing commas in a listEnd: CommaThe comma at the end of each line is removed
Values wrapped in quotesWrappersMatching outer quotes or brackets removed
Timestamp at the start of log linesRemove a set number of characters, From the startThe first N characters of each line are cut
Blank lines at the top and bottom of a blockWhole text, Both endsOnly the edges of the block are trimmed

Each line or Whole text?
Use Each line for lists and tables where every row has its own padding. Use Whole text for an article or message where you only want to clean the beginning and end of the block.

Text is processed in your browser. Nothing is uploaded.

Non-breaking spaces, zero-width characters, and trailing commas

The characters that look like nothing, and what each one breaks.

Non-breaking space (CHAR 160) versus a regular space

A non-breaking space is the character behind &nbsp; in HTML and is code 160 in Excel. It looks like a space but is a different character. Microsoft notes that TRIM removes the ASCII space (code 32) and does not remove it by itself.
Text copied from web pages, PDFs, and emails often contains them, so a value can look clean and still fail an exact match.

Zero-width spaces and the byte order mark

Zero-width characters take up no room on screen, so a cell with one looks identical to a cell without it, yet the two are different strings and have different lengths.
The Hidden character check counts zero-width spaces, joiners, the word joiner, and the byte order mark in your input so you can see them before you trim.

Why CLEAN does not replace this

Excel CLEAN removes the first 32 non-printing characters (codes 0 to 31), including the line feed. It does not remove the non-breaking space.
A common fix is =TRIM(SUBSTITUTE(A2,CHAR(160)," ")). Doing the same on a pasted list here avoids writing that formula for every column.

Trailing commas in lists and JSON

A comma left after the last item of a list is a common cause of parse errors. Standard JSON does not allow a trailing comma.
The End: Comma button removes the comma from the end of every line, including lines that should keep it, so use it when none of the lines should end with one.

Why trimmed data still won't match

TRIM was applied, but VLOOKUP still returns #N/A

Excel TRIM removes the regular space but not a non-breaking space or a zero-width character. The cell looks clean, yet it differs from the lookup value by a hidden character.

💡 See the solution▼
Paste the column here with Each line selected and look at the Hidden character check. If it shows non-breaking or zero-width characters, keep the non-breaking and zero-width switch on, trim, and paste the result back.

Indentation lost in code, YAML, or Markdown

Each line with Both ends removes leading spaces, so nested items in code, YAML, or a Markdown list become flat and can change meaning.

💡 See the solution▼
Choose End only. It removes trailing whitespace and leaves the leading spaces where they are.

Parentheses or quotes removed from the text itself

The Wrappers option removes any matching pair around the whole line. A line such as (a) and (b) starts and ends with parentheses, so it comes out as a) and (b.

💡 See the solution▼
Turn Wrappers off for text that may contain its own outer brackets, or use it only on lists where every value is wrapped the same way.

Only the edges of the block were cleaned

Whole text trims just the beginning and end of everything you pasted, so spaces at the start of each inner line stay.

💡 See the solution▼
Switch to Each line. Use Whole text only when you want to remove blank lines or spaces from the very start and very end of the block.

Trim text FAQ

Q.How do I remove leading and trailing spaces from every line?

Q.

A. Paste your text, leave the scope on Each line, and leave the end on Both ends. Spaces, tabs, non-breaking spaces, and zero-width spaces are trimmed from the start and end of every line, and the line breaks stay in place. A line that held only whitespace becomes an empty line, so turn on Remove empty lines if you want those gone too.

Q.Does it remove the spaces between words?

Q.

A. No. Only the start and end of each line (or of the whole text) are trimmed. Spaces inside a line are left alone unless you turn on Merge repeated spaces, which replaces a run of two or more spaces, tabs, or non-breaking spaces with one space. A single space between words is never touched.

Q.Why does Excel TRIM leave spaces that break my VLOOKUP?

Q.

A. Microsoft says TRIM was designed to remove the ASCII space character (code 32). A non-breaking space (code 160), which text from web pages often contains, is not removed, so the cell looks clean but still does not match. Paste the column here with Each line selected, check the Hidden character check for non-breaking spaces, and paste the result back. In Excel itself you can use =TRIM(SUBSTITUTE(A2,CHAR(160)," ")).

Q.Can I trim only the start or only the end of the text?

Q.

A. Yes. Choose Start only to remove indentation and leave trailing spaces, or End only to remove trailing spaces and leave the indentation in place. End only is the safer choice for code, YAML, or Markdown, where leading spaces carry meaning.

Q.Which characters count as whitespace?

Q.

A. Each type has its own toggle. Spaces, tabs, and the ideographic space (U+3000) are separate switches. The non-breaking and zero-width switch covers the non-breaking space, en, em, thin, and hair spaces, the zero-width space and joiners, the narrow no-break space, the word joiner, and the byte order mark. Line breaks are trimmed only in Whole text mode.

Q.How do I remove bullets, list numbers, or > quote marks from the start of lines?

Q.

A. Turn on the matching Start button under Remove specific characters: Quote mark >, Bullets, List numbers, or Markdown # headings. A hyphen, asterisk, or plus sign is removed only when a space follows it, and a number such as 3.5 is left alone. With Repeat while it still matches on, nested quotes like > > are removed in one pass.

Q.How do I remove the trailing comma, semicolon, or period from every line?

Q.

A. Turn on the matching End button: Comma, Semicolon, or Period. Only the last character of a line is checked. With Repeat while it still matches on, a line ending in ... loses all three periods, so turn that option off if you want to remove just one.

Q.Can I remove the first or last few characters of each line?

Q.

A. Yes. Enter a number under Remove a set number of characters. The count starts after whitespace has been trimmed, so it counts from the first visible character. Each Unicode code point counts as one character, so an emoji built from several code points counts as more than one. This works for timestamps or fixed-length IDs at the start of log lines.

Q.What is the difference between Each line and Whole text?

Q.

A. Each line trims every line separately. Whole text treats everything you pasted as one block and trims only its very start and very end, including blank lines there. Characters you ask to remove, and the character counts, are also applied once to the whole block in that mode.

Q.Is my text uploaded anywhere?

Q.

A. No. The tool processes your text with JavaScript in your browser and has no upload step. The text stays in the page while it is open, and closing or reloading the page clears it.

User Feedback & Request

Your feedback
makes this tool better.

Tell us which features you'd like, what should be fixed, or which new tool you'd like to see. An engineer reads every submission and uses it to guide development.

Send feedback