String Space Replacer

Replaces every literal space character in your text with a custom replacement string, such as an underscore or hyphen, useful for building slug-like tokens, filenames, or identifiers out of plain text. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-23

Overview

Introduction

Turning a sentence or phrase into a slug, filename, or identifier usually starts with getting rid of literal spaces.

This tool does that in one step, and runs entirely client-side, so nothing you paste is ever uploaded to a server.

What Is String Space Replacer?

A find-and-replace tool specialized for the space character: it swaps every literal space in your text for a replacement string you choose.

It's part of this site's String Tools collection and works entirely in your browser.

How String Space Replacer Works

The tool splits the input on the space character and rejoins the pieces using your replacement string in place of each gap.

The transformation happens synchronously in JavaScript the moment you type, with no network round trip involved.

When To Use String Space Replacer

Use it when you need to convert a phrase into a slug-like token, such as turning 'my file name' into 'my_file_name'.

It's also handy for quickly building identifiers, tags, or filenames out of freeform text.

Often used alongside Whitespace Trimmer and Whitespace Remover.

Features

Advantages

  • Works with any replacement string, not just a fixed underscore.
  • Simple, predictable, single-character-class replacement.
  • Substitutes literally through a split and join, so a replacement containing regex-special characters is inserted exactly as typed.

Limitations

  • Only targets the literal space character; other whitespace like tabs and newlines are untouched.
  • Doesn't lowercase or otherwise sanitize the text, unlike a full slugify tool.

Examples

Replacing spaces with underscores

Input

my file name

Output

my_file_name

Every space is replaced with the chosen replacement string, here an underscore.

Best Practices & Notes

Best Practices

  • Use Slugify a String instead if you also need lowercasing and character sanitization for URLs.
  • Choose a replacement that won't collide with characters already in your text if the result needs to be reversible.
  • Collapse runs of spaces before converting, otherwise a double space yields two separators and breaks an otherwise clean identifier.

Developer Notes

The implementation is `input.split(" ").join(replacement)`, which handles any replacement string (including a multi-character one or an empty string) without regex escaping concerns.

String Space Replacer Use Cases

  • Converting a phrase into a slug-like token
  • Building a filename out of freeform text
  • Creating an identifier from a multi-word label

Common Mistakes

  • Expecting tabs or newlines to also be replaced; only literal spaces are affected.
  • Using this for URL slugs when full slugification (lowercasing, removing special characters) is actually needed.

Tips

  • Combine with a case converter afterward if you want a fully normalized slug, like lowercase with underscores.
  • Leaving the replacement empty removes the spaces altogether, turning a phrase into a single unbroken token.

References

Frequently Asked Questions