Substring - Substring

Substring

A substring (or factor) of a string is a string, where and . A substring of a string is a prefix of a suffix of the string, and equivalently a suffix of a prefix. If is a substring of, it is also a subsequence, which is a more general concept. Given a pattern, you can find its occurrences in a string with a string searching algorithm. Finding the longest string which is equal to a substring of two or more strings is known as the longest common substring problem.

Example: The string ana is equal to substrings (and subsequences) of banana at two different offsets:

banana ||||| ana|| ||| ana

In the mathematical literature, substrings are also called subwords (in America) or factors (in Europe).

Not including the empty substring, the number of substrings of a string of length where symbols only occur once, is the number of ways to choose two distinct places between symbols to start/end the substring. Including the very beginning and very end of the string, there are such places. So there are non-empty substrings.

Read more about this topic:  Substring