# List all substrings of a number

Need some help listing all substrings of a number

X=219 The output should be

Output= {2,21,219,1,19,9}

Order does not matter for this problem Any help is appreciated

You can use a combination of IntegerDigits + Subsequences + FromDigits:

FromDigits /@ Rest @ Subsequences[IntegerDigits @ #] & @ 219

{2, 1, 9, 21, 19, 219}

X = 219;

FromDigits /@ ReplaceList[IntegerDigits[X], {___, x__, ___} -> {x}]


{2, 21, 219, 1, 19, 9}

Subsets[IntegerDigits@219, {1, 3}]


gives

{{2}, {1}, {9}, {2, 1}, {2, 9}, {1, 9}, {2, 1, 9}}


If you do not want the three-length set, then use

Subsets[IntegerDigits@219, {1, 2}]

X = 219;
Y = IntegerDigits[X];
FromDigits /@(Y[[#[] ;; #[]]] & /@
Flatten[Table[{i, j}, {i, 1, Length[Y]}, {j, i, Length[Y]}], 1])


gives

{2, 21, 219, 1, 19, 9}


Note that

Flatten[Table[{i, j}, {i, 1, Length[Y]}, {j, i, Length[Y]}], 1]


is

{{1, 1}, {1, 2}, {1, 3}, {2, 2}, {2, 3}, {3, 3}}


the set of pairs of starting position and ending position.