Skip to content

Substring

A string value occurring as a contiguous factor of a host, including the empty value by convention.

Version
v1 · 2026-09-28 · History
Domain-specific #
12349
Domain group
Applied Sciences & Engineering
Origin domain
Computer Science & Software Engineering
Subdomain
Formal Languages and String Algorithms → Computer Science & Software Engineering
Aliases
Factor of a string, Subword

Core Idea

A substring is a contiguous factor of an ordered string. Formally, u occurs in host t when the host can be decomposed as p followed immediately by u followed immediately by s, with p and s possibly empty. This includes prefixes, suffixes, the entire host, and—under the usual stated convention—the empty string. It excludes a subsequence that keeps symbol order but skips positions.

A substring value and its occurrence are not the same object: ana is one string value that appears twice in banana. Pattern-searching algorithms use this relation when locating all contiguous occurrences of a query pattern in text. The formal statement assumes an alphabet and segmentation of symbols; code units, Unicode characters, and grapheme clusters can differ in real text systems, so a computational implementation must state which sequence it searches.

How would you explain it like I'm…

A No-Gaps Word Piece

A substring is a piece of a word where the letters sit right next to each other, with no gaps. In 'banana', 'nan' is a substring. But 'bnn' is not, because it skips letters in between.

No-Skipping Word Pieces

In computer science, a string is a row of characters, like a word or sentence. A substring is a chunk of that row where the characters are all next to each other, with no gaps. The beginning of the string, the end, and even the whole string count as substrings. If you pick letters in order but skip some, like 'bnn' from 'banana,' that's called a subsequence, not a substring. Also, one substring can show up more than once: 'ana' appears twice in 'banana.'

Contiguous Piece of a String

A substring is a contiguous piece of a string: the string u is a substring of t if t can be split as p, then u, then s, with nothing in between, where p and s can be empty. That means prefixes, suffixes, the whole string and (by the usual convention) the empty string all count. It differs from a subsequence, which keeps the order of characters but may skip positions. A substring as a value is different from an occurrence: 'ana' is one value with two occurrences in 'banana'. Search algorithms find every position where a pattern occurs as a substring of a text. In real software you must also decide what counts as one 'character', since code units, Unicode characters and visible letters can differ.

 

A substring is a contiguous factor of a string: u occurs in t iff t = p·u·s for some (possibly empty) strings p and s. This includes prefixes (p empty), suffixes (s empty), t itself, and conventionally the empty string, but excludes subsequences that preserve order while skipping positions. The relation is distinct from its occurrences: a single substring value like 'ana' may occur at multiple overlapping positions in 'banana'. Pattern-matching algorithms are built on this relation, locating all contiguous occurrences of a pattern in a text. The definition presupposes a fixed alphabet and segmentation of symbols; in real text systems, code units, Unicode code points and grapheme clusters can segment differently, so implementations must specify which sequence they operate on.

Scope of Application

Substring reasoning applies after a host string and its symbol units are fixed.

  • Formal languages. Reason about factors, prefixes, suffixes, and word equations.
  • Pattern matching. Locate all contiguous query-string occurrences in a host.
  • Text processing. Extract spans while documenting character or grapheme indexing conventions.
  • Comparative string problems. Distinguish longest common substring from longest common subsequence.

Clarity

Show t=p u s with p and s possibly empty. Ana is one substring value of banana at two offsets; a subsequence that skips a symbol is the closest exclusion. Prefixes and suffixes are included positional cases, and the empty string qualifies by the stated convention. In software, byte, code-point, and grapheme indexing may differ, so specify the symbol unit before reporting spans.

Manages Complexity

The factor relation compresses ordered adjacency and host-relative position into one term. It supports concise pattern-search and combinatorics claims, but can hide whether an analysis counts values, occurrences, or implementation-specific text units. Restating the host, factor, and span makes the relation computable without conflating those choices.

Abstract Reasoning

  1. Fix the host string and the alphabet or text-segmentation unit.
  2. Choose candidate u and search for an uninterrupted matching span.
  3. Exhibit p and s such that t=p u s, including empty boundary pieces if needed.
  4. Separate the factor's symbol value from every occurrence offset.
  5. Reject ordered-but-gapped subsequences and state the empty-string convention.

Knowledge Transfer

The contiguous-factor test transfers across formal strings, program tokens, and encoded text only after the symbol unit is specified. The ana-in-banana offsets do not carry to a differently normalized text representation, and a KMP occurrence claim does not include gapped subsequences. The general part-whole intuition is broader but lacks the exact t=p u s condition.

Neighborhood in Abstraction Space

Substring sits in a crowded region of the domain-specific corpus (32nd percentile for distinctiveness): several abstractions share nearly its structure, so a description that fits it tends to fit its neighbors too.

Family — Language Structure & Grammar Formalisms (23 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14