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.

Structural Signature

Sig role-phrases:

  • Host string and alphabet — Fixes the finite ordered symbol sequence and what counts as one symbol. It is constitutive. Counterfactual: Without a host and symbol convention, contiguity cannot be tested.
  • Candidate factor — Supplies the string u being tested as a contiguous part of the host. It is constitutive. Counterfactual: A bag of letters without order is not a substring value.
  • Contiguous occurrence span — Identifies adjacent host positions equal to nonempty u, or a zero-length boundary span when u is empty by convention. It is constitutive. Counterfactual: Skipping intervening host symbols yields only a subsequence, while excluding zero-length spans would contradict the stated empty-factor convention.
  • Prefix/suffix decomposition — Expresses the exact factor relation t=p u s, allowing empty p or s. It is central. Counterfactual: A set-membership statement without contiguous decomposition misses the formal condition.
  • Occurrence and boundary convention — Distinguishes one substring value from multiple positions and includes the empty factor convention. It is boundary. Counterfactual: Treating two ana positions as different string values or excluding empty u silently changes the stated definition.

What It Is Not

  • Not any subsequence. Skipping an intervening host symbol breaks contiguity.
  • Not an occurrence index. The same substring value can appear at multiple positions.
  • Not merely shared letters. Order and adjacent placement both matter.
  • Not a segmentation-free text fact. An implementation must define the symbol unit being searched.
  • Closest near-miss. Subsequence is the closest neighbor: it preserves order but may omit intervening symbols; substring requires an uninterrupted host interval.

Scope of Application

  • 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

Test t=p u s with p and s allowed to be empty. Ana is a substring of banana at two offsets but remains one factor value; the empty string is included by convention. A scattered ordered selection is the nearest excluded subsequence. Prefix and suffix are included positional special cases. For real text, state whether symbols are bytes, code points, or grapheme clusters before comparing indices.

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.

Examples

Canonical

In banana, ana occurs contiguously at positions 2–4 and 4–6 under one-based character indexing. The same factor value u=ana therefore has two occurrence spans: b·ana·na and ban·ana. A sequence bnn can preserve some letter order yet is not a contiguous factor if intervening positions are skipped. The empty string qualifies by taking u empty in t=p u s, occupying a zero-length boundary span rather than a skipped-letter interval.

Mapped back: Host string and alphabet → banana over character alphabet; Candidate factor → u=ana, with empty u considered separately; Contiguous occurrence span → positions 2–4 and 4–6 for ana; zero-length boundary span for empty u; Prefix/suffix decomposition → b·ana·na and ban·ana·empty; Occurrence and boundary convention → one ana value, two offsets; empty factor allowed by convention.

Applied / In Practice

Knuth, Morris, and Pratt's 1977 pattern-matching paper studies the computational task of finding every occurrence of one string inside another. The target pattern is a substring only at contiguous matching spans of the text; their algorithm reports occurrences under a formal string model rather than treating a scattered subsequence as a hit. The published linear-time claim concerns that matching problem, not every string operation or Unicode segmentation rule.

Mapped back: Host string and alphabet → paper's text string over a fixed alphabet; Candidate factor → pattern string; Contiguous occurrence span → reported matching positions; Prefix/suffix decomposition → text split around each matched pattern; Occurrence and boundary convention → all occurrences located, even when pattern value repeats.

Structural Tensions

T1 — Factor Value versus Occurrence Position. A repeated substring can be one symbol sequence with many positions, so counting distinct values and counting matches are different tasks.

Diagnostic: Is the report counting strings or offsets?

T2 — Formal Symbol versus Human-Text Unit. Code units, Unicode scalar values, and user-perceived graphemes segment text differently, affecting apparent contiguity.

Diagnostic: What alphabet and segmentation define one symbol?

Structural–Framed Character

The skeleton is a contiguous selected value within an ordered host. A substring u of t satisfies t=p u s for possibly empty prefix and suffix; positions of occurrences are separate from the value u. It is an approved unparented root because Relation classifies the binary membership relation, not the string value.

Evaluative weight: Contiguity is exact, not an interpretive resemblance.

Human-practice-bound: Symbol unit and normalization must be fixed before comparing encoded texts.

Institutional origin: Formal-language definitions specify concatenation and the empty-string convention.

Vocabulary travels: “Subsequence” may allow gaps and is not interchangeable with substring.

Import versus recognize: Contiguous-factor reasoning transfers to tokens or text once the alphabet and equality rule are specified.

Its character: A formal string factor value, not a prime part-whole relation.

Structural Core vs. Domain Accent

Skeletal core. An ordered whole can contain a contiguous component.

Domain-bound accent. In string theory that component is a string u for which t=p u s, with exact symbol equality and concatenation. One value may occur at several positions.

Why not prime. Spatial parts or thematic excerpts need not satisfy string concatenation, and the “is a substring of” relation is a different typed object from u itself.

  • Related — subsequence. Both preserve order, but only substring requires adjacent host positions.

  • Related — prefix and suffix. They are substrings constrained to the start or end of the host.

Neighborhood in Abstraction Space

Substring sits in a crowded region of the domain-specific corpus (37th 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-10-08

Not to Be Confused With

  • Subsequence. Tell: Were any intervening host symbols skipped?
  • Prefix. Tell: Must the occurrence begin at the host's first position?
  • Occurrence. Tell: Is this a string value or one indexed location of that value?
  • Character cluster. Tell: Which text unit is one formal symbol?

References

  • Knuth, Morris, and Pratt, Fast Pattern Matching in Strings, SIAM Journal on Computing 6 (1977): https://epubs.siam.org/doi/10.1137/0206024
  • Frozen Wikipedia discovery revision: https://en.wikipedia.org/wiki/Substring (revision 1356353961).