-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallSubstrings.cs
36 lines (36 loc) · 1.09 KB
/
allSubstrings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* C# Program to List all Substrings in a given String
*/
//Will combinatorically generate all substrings of a given string.
using System;
namespace mismatch
{
class Program
{
string value, substring;
int j, i;
string[] a = new string[5];
void input()
{
Console.WriteLine("Enter the String : ");
value = Console.ReadLine();
Console.WriteLine("All Possible Substrings of the Given String are :");
for (i = 1; i <=value.Length; i++)
{
//Nested loops guarantee all of the substring indices will be created.
//This is runtime of O(n^2) in terms of number of characters.
for (j = 0; j <= value.Length - i; j++)
{
substring = value.Substring(j, i);
a[j] = substring;
Console.WriteLine(a[j]);
}
}
}
public static void Main()
{
Program pg = new Program();
pg.input();
Console.ReadLine();
}
}