Skip to content

Substring Extractor

Extract a substring by position.

Text
Start
Length
Output

No result

About Substring Extractor

Substring Extractor pulls a defined slice out of a longer string by position: you give it where to start and how many characters to take, and it returns that span. It is the tool for pulling a fixed-width field out of a data record, a prefix out of an identifier, or a segment out of a line of fixed-format output.

Positions are counted from zero, so the first character of the string is position zero and a start of five takes you to the sixth character. That convention is worth stating because counting from one is just as common in the world of fixed-width fields, and the two differ by exactly one character at the boundary.

Positions are measured in the units the underlying string uses rather than in visible characters, so a character outside the basic Latin range occupies two positions. For text containing emoji or rare scripts, a start or length that was calculated from a visible character count will land in a different place than expected. Plain Latin text has no such discrepancy.

Two inputs are accepted and no more: where to start and how many characters to take. That rules out several neighbouring jobs. You cannot give the tool two markers and have it return what sits between them, you cannot slice on a repeated pattern, and you cannot extract several non-adjacent spans in one pass — anything of that shape needs a find-and-replace or a regex runner instead. There is also no before-and-after view showing the discarded portion, so if the numbers were wrong the only evidence is a result that looks slightly off; compare it against the source text before relying on it.

How to use Substring Extractor

  1. 1 Paste the string you want to slice.
  2. 2 Enter the start position, counting the first character as zero.
  3. 3 Enter how many characters to take.
  4. 4 Check the result against the original if it contains characters outside the Latin range.

Frequently asked questions

Is the first character position zero or one?

Zero. Counting from zero is the convention used by most programming languages, so a start value carried over from one of those will behave as you expect. A value taken from a one-based specification needs one subtracted before it goes in.

What happens if the length runs past the end of the string?

You get whatever remains. The slice ends at the end of the string rather than padding the result out to the requested length, so a short result tells you the length was longer than the text rather than indicating an error.

Why is my slice off by one character?

The most common cause is a start position written for one-based counting. The second most common is a string containing characters outside the basic Latin range, each of which occupies two positions. Check both before changing the numbers.

Can I extract a substring between two markers?

Not directly, since this works by position rather than by pattern. Find the offsets of your markers in the source, then use the difference between them as the start and length.

Free, online, and private

Free to use

Substring Extractor is completely free. There is no account to create, no login, and no hidden charge or usage limit.

Runs online in your browser

It is a free online tool that runs entirely in your browser. Nothing to download or install — open the page and start using it right away.

Your data stays private

All processing happens locally on your device. Your input is never uploaded, stored, or tracked, so it never leaves your browser.

How Substring Extractor behaves in detail

These are the specifics of this implementation — the exact ranges, defaults and fixed settings you are working with.

Parameter Value
Indexing zero-based — Start 0 is the first character, and the defaults Start 0 with Length 5 return "Hello"
What the second number means a span of characters from Start, not an end position; the end index is computed as Start plus Length
Field bounds Start and Length are both numbers with min 0 and no maximum; Text defaults to "Hello world", Start to 0 and Length to 5
Out-of-range input resolved by slice — a Start beyond the end of the text returns an empty result instead of an error
Unreadable values a value that is not a finite number falls back to Start 0 and Length 5, which matches the declared defaults

Compiled from the implementation of this tool and checked against it by itoolnet.

What Substring Extractor does not do

Knowing the edges of a tool saves more time than another list of its features. These are the cases where it will not do what you might expect.

  • Positions are counted in UTF-16 code units, not in characters. A non-BMP character such as an emoji occupies two positions, so a Start or an end index that lands inside one returns half of it — a lone surrogate that will not render or copy as the original glyph.
  • The minimum of 0 on Start is a form constraint rather than a guarantee. If a negative number reaches the code, slice() resolves that offset from the end of the string while the end index is computed from the same negative value, so the two bounds come from opposite ends and the result is empty or a single stray character.
  • The substring cannot be described by content. There is no delimiter, no regular expression and no "between these two words" mode, and no offset ruler shows which character sits at which position, so the two numbers have to be worked out beforehand from a separate count.

Tested and documented by itoolnet, the team that builds and maintains this site.

Share & embed this tool

Writing a guide or article? You are welcome to link to Substring Extractor with the snippet below. It is free, runs entirely in your browser, and needs no signup.