A substring of a string S {\displaystyle S} is a string S ′ {\displaystyle S'} that occurs "in" S {\displaystyle S} . For example, "the best of" is a substring of "It was the best of times". This is not to be confused with subsequence, which is a generalization of substring. For example, "Itwastimes" is a subsequence of "It was the best of times", but not a substring.
Prefix and suffix are special cases of substring. A prefix of a string S {\displaystyle S} is a substring of S {\displaystyle S} that occurs at the beginning of S {\displaystyle S} . A suffix of a string S {\displaystyle S} is a substring that occurs at the end of S {\displaystyle S} .
The list of all substrings of the string "apple" would be "apple", "appl", "pple", "app", "ppl", "ple", "ap", "pp", "pl", "le", "a", "p", "l", "e", "".