Do not stress over this, do it if you find it enjoyable. I think it is a fun problem.
Let's say I have a random string "abv". It can have any text characters instead of "a", "b" and "v", and it can be any length. I want to divide it into many combinations of strings like this below.
I also want to save "spaces" (that something is there, the string continues) and "end" (that there are no more characters before/after it, the string ends there). In this case - I represent "space" with "0" and "end" with "-".
On the left is the same thing but with serial numbers, just for the extra comparison in order to explain what I really want. The first row in every section, marked with "#" is just for the explanation, it shows the string the code is working on in the (current) section.
Worry not about the performance.
So, because of "ends", represented with "-", I would actually have exactly the same thing but with two more characters on each end, "abv" would actually be "-abv-", so it is many many more strings. Therefore - a string "abv" would be considered as "-abv-", which is of length 5, somewhat.
Text characters can repeat but they all sort of have own spot.
Strings that are repeating I do not want to be saved again, but I want to add a counter to each string that counts how many times it was gotten (repeated), I think I could do the counter myself, but for those who like even deeper problems - here you go.
For example, Working with this "abv", first working with "a" gives two strings: "0" and "a", next, working with just "b" gives again two strings: "0" and "b", in this case, "space" (or "0") is repeating, so we just increase the counter for it by one instead of saving it as a string by itself, so we get: "0=2", "a=1", "b=1", so eventually, in this case there will be strings saved as: "-ab", "abv-" and so, see the chart below of all possible combinations with the string "abv".