String Slicer

Extracts a substring using JavaScript's slice() semantics: a start index, an optional end index, and support for negative indices counting from the end. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-22

Overview

Introduction

Extracting a piece of text by index is one of the most common string operations in code, and this tool mirrors JavaScript's own slice() semantics exactly, including negative index support.

It runs entirely client-side, so nothing you paste is ever uploaded to a server.

What Is String Slicer?

A substring extractor matching String.prototype.slice(start, end): positive indices count from the start, negative indices count from the end.

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 String Slicer Works

The input is split into an array of Unicode code points, sliced between the given start and end indices, and rejoined.

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

When To Use String Slicer

Use it to test what a slice(start, end) call would return before writing the equivalent code, or to quickly extract a known range from text.

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 Substring Extractor and String Truncator.

Features

Advantages

  • Matches JavaScript's native slice() behavior exactly, including negative indices.
  • Operates on Unicode code points rather than raw UTF-16 units.
  • Leaving the end index off takes everything through to the end of the string, matching the native method and saving a length calculation.

Limitations

  • Requires knowing the exact index range you want; for a fuzzy 'find this text' extraction, use Find and Replace or a regex tool instead.
  • Indices count code points rather than bytes, so they will not line up with offsets taken from a byte-oriented tool or a hex dump.

Examples

Slicing a fixed range

Input

Hello, world!

Output

Hello

start=0, end=5 extracts the first five characters.

Slicing with a negative index

Input

Hello, world!

Output

world!

start=-6 extracts the last six characters, matching JavaScript's negative-index convention.

Best Practices & Notes

Best Practices

  • Use negative indices when you want to extract relative to the end without first computing the string's length.
  • Use a negative start to take a fixed number of trailing characters without needing to know the total length first.
  • Test the indices against a representative sample before applying them to a batch, since an out-of-range end quietly returns a shorter result.

Developer Notes

The implementation spreads the input into code points ([...input]) before slicing, so multi-byte characters like emoji aren't split apart the way a naive index into the raw UTF-16 string could.

String Slicer Use Cases

  • Testing a slice(start, end) expression before writing code
  • Extracting a known-position substring from text
  • Trimming a fixed number of characters from either end

Common Mistakes

  • Confusing this with substr()-style start+length semantics; use Extract a Substring for that instead.
  • Passing a start greater than the end and expecting the range to be read in reverse; that combination simply returns an empty string.

Tips

  • Use Extract a Substring instead if you're thinking in terms of a starting position and a length rather than two indices.
  • Because it splits by code point, an emoji occupies a single position here even though most byte-based editors count it as two.

References

Frequently Asked Questions