To find all substrings in a given string

Suppose a long string is given, I want to find all substrings has a fixed length.
For example,
string line = "abcdefghabcdegfh5678jhqwi5436";

Open in new window

find substrings that have length 5.
The results are

Who is Participating?
Below an example with a very easy loop ....
string line = "abcdefghabcdegfh5678jhqwi5436";
            List<string> lineList = new List<string>();

            for (int i = 0; i < line.Length-5+1; i++)

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.