# Find all substrings from a string by deleting characters from it

Problem Description : I need to create all substrings from a string by deleting letters from it without re-arranging the rest of the letters. For example, "us" is a substring of "substring", but "gs" is not . Duplicates should be counted. For example, "peep" has two substrings "pep", corresponding to the two choices of "e". The code below I ran does not give me desired output.

subString[s_String] := StringCases[s, {_, __}, Overlaps -> All]


I would appreciate if anyone can help.

• subString[s_String] := Map[StringJoin, Subsets[Characters[s]]] – user3257842 Jun 10 at 15:42
• I think you are correct, I added remove the empty element in the list in code below. Thank you very much. – Normal Student Jun 11 at 14:39

DeleteCases[Map[StringJoin, Subsets[Characters[s]]], ""]