行の前後の空白を消す方法
- 貼り付ける
- 空白を消す
- コピーする
コピーしたリストの行頭や行末に、見えない空白が入っていると、同じ内容でも別の行と判断されます。重複した行を消す・並べ替える の「行の前後の空白を消す」で、取り除けます。
手順
- 「整える前(1行に1つ)」に、リストを貼り付けます。
- 「行の前後の空白を消す」にチェックを入れます。
- 必要なら、「重複した行を消す」「空行を消す」も選びます。
- 「整えた後」を確認し、「結果をコピー」でコピーします。
空白が入る原因
- PDFやWebページからコピーした
- Excelのセルに、スペースが入っていた
- 手入力で、うっかり入った
- 整形のために、字下げがされていた
空白の種類
- 半角スペース
- 全角スペース
- タブ
見た目では分かりにくいものがあります。
重複と組み合わせる理由
「山田太郎」と「山田太郎 」(末尾にスペース)は、別の行として扱われ、重複とみなされません。先に空白を消すと、同じ行として、重複を取り除けます。
文字のあいだの空白
行の中の空白を消したいときは、置換機能の付いたテキストエディタや、全角・半角を整えるツールを使います。
向いている場面
- 名簿の照合前に、整える
- Excelに貼り付ける前に、整える
- キーワードリストの整理
- 重複チェックの前処理
例
参加者名簿を2つ合わせたら、重複が見つからなかった。末尾の空白が原因と分かり、「行の前後の空白を消す」を選んだところ、15行の重複が見つかった。
つまずきやすい点
- 空白を消しても重複が残る:全角・半角の違いがある。
- 文字の間の空白は残る:行の前後だけが対象。
- 見えない文字:特殊な空白は、残る場合がある。
よくある質問
全角スペースも消えますか?
はい。行頭・行末の空白は、全角も含めて取り除かれます。
まとめ
重複チェックの前に、前後の空白を消す。見えない空白が、重複を隠しています。
重複した行を消す・並べ替えるを使う(無料)あわせて使えるツール
- 文章の改行を消す・整える:PDFなどからコピーした文章の改行を整えます。
- 文字数カウント(エントリーシート・レポート用):文章の文字数・行数・原稿用紙の枚数などを数えます。
- 全角・半角、ひらがな・カタカナを変換する:全角・半角、ひらがな・カタカナを変換します。
同じツールの、ほかの解説
How to Trim Spaces Around Lines
- Paste
- Trim spaces
- Copy
If a copied list has invisible spaces at the start or end of lines, even identical content is judged as different lines. "Remove spaces at the start and end of lines" in Remove Duplicate Lines and Sort a List takes them out.
Steps
- Paste the list into "Before tidying (one per line)".
- Tick "Remove spaces at the start and end of lines".
- If needed, also choose "Remove duplicate lines" and "Remove empty lines".
- Check "After tidying" and copy with "Copy result".
Why spaces get in
- Copied from a PDF or web page
- A space was in an Excel cell
- Slipped in through manual input
- Indented for layout
Kinds of spaces
- Half-width space
- Full-width space
- Tab
Some are hard to see.
Why combine with duplicates
"Yamada Taro" and "Yamada Taro " (trailing space) are treated as different lines and not seen as duplicates. Removing the spaces first makes them the same line so the duplicate can be removed.
Spaces between characters
To remove spaces inside a line, use a text editor with find-and-replace or the tool that tidies full-width and half-width.
Good for
- Tidying before matching a roster
- Tidying before pasting into Excel
- Tidying a keyword list
- Preprocessing before a duplicate check
Example
Merging two rosters found no duplicates. Trailing spaces were the cause; after choosing "Remove spaces at the start and end of lines", 15 duplicate lines were found.
Common stumbling blocks
- Duplicates remain after removing spaces: full-width/half-width differences.
- Spaces between characters remain: only the start and end of lines are targeted.
- Invisible characters: special spaces may remain.
Frequently asked questions
Are full-width spaces removed too?
Yes. Spaces at the start and end of lines, including full-width, are removed.
Summary
Remove surrounding spaces before a duplicate check. Invisible spaces hide duplicates.
Use "Remove Duplicate Lines and Sort a List" (free)Tools that go well with this
- Remove and Tidy Line Breaks in Text: Tidy line breaks in text copied from PDFs and elsewhere.
- Character Counter (for Applications and Reports): Count characters, lines and manuscript sheets of your text.
- Convert Full-Width, Half-Width, Hiragana and Katakana: Convert full-width/half-width and hiragana/katakana.