15,610,475 members
See more:
I just need an idea about how to approach!!!

What I have tried:

Nope!!
I’m having no idea!!
Don’t no how to approach for it and get started!!
Posted
Updated 18-Feb-18 21:56pm
Daniel Pfeffer 18-Feb-18 15:16pm
How would you do this by hand?
For example, take the string "abc". How would you extract all of the substrings? Now do the same for "abcd". Do you see the pattern?

Now write it in code.
PIEBALDconsult 18-Feb-18 16:48pm
Not enough information.
[no name] 18-Feb-18 18:44pm
You may know the EXACT requirement. We don't. Give some examples with outputs you expect.
Rick York 19-Feb-18 14:21pm
The first thing I would do is get an exact definition of the word substring. There are several possibilities and it is not exactly clear which one you want in this case.

## Solution 5

Quote:
How to find all substrings of a given string

With a sheet of paper and a pencil, you get something like:
- imput string= "abcdef"
- substrings: "a" "ab" "abc" "abcd" "abcde" "abcdef" "b" "bc" "bcd" "bcde" "bcdef" "c" "cd" "cde" "cdef" "d" "de" "def" "e" "ef" "f"
- find which operations give the substrings in order and what are the changes between 2 of them.
- deduce the algorithm and write code.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.

## Solution 1

Go recursive.
If you don't know recursion then have a look at Recursion (computer science) - Wikipedia[^].

PIEBALDconsult 18-Feb-18 16:11pm
NO!
CPallini 19-Feb-18 4:43am
Why not?
PIEBALDconsult 19-Feb-18 8:59am
Unnecessary.

## Solution 4

A brute force approach would be to use two loops.

outer loop goes from 0 to len-1,
inner loop goes from outer-loop-var to len-1
extract substring using the two loop variables as start and end index (use strncpy)

This should work in any language, and your choice seems to be C.

v2
PIEBALDconsult 18-Feb-18 21:09pm
inner loop goes from 0 to len-<outer loop variable> ?
or
inner loop goes from <outer loop variable> to len-1 ?
Nish Nishant 19-Feb-18 10:22am
Oops, you are right. I'll edit it :-)

## Solution 6

Finding substrings in C is the task of the function strok.
As delimiter you should use the space " ".

Some tutorial on strtok. On this site you can also learn the basics of the language C.

Another question is, what you mean with "finding substrings". You can use other strings as delimiter in strtok.

## Solution 3

```static void Main(string[] args)
{
const string word = "abcdef";
for (int i = 0; i < word.Length; i++)
Console.WriteLine(word.Substring(0, i + 1));
}
```