

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to find all substrings in a string
Use the substring() method in C# to find all substrings in a string.
Let’s say our string is −
Xyz
Loop through the length of the string and use the Substring function from the beginning to the end of the string −
for (int start = 0; start <= str.Length - i; start++) { string substr = str.Substring(start, i); Console.WriteLine(substr); }
Example
The following is the C# program to find all substrings in a string.
using System; class Demo { static void Main() { string str = "xyz"; for (int i = 1; i < str.Length; i++) { for (int start = 0; start <= str.Length - i; start++) { string substr = str.Substring(start, i); Console.WriteLine(substr); } } } }
Output
x y z xy yz
- Related Questions & Answers
- Find all substrings in a string using C#
- Program to find all substrings whose anagrams are present in a string in Python
- Program to print all substrings of a given string in C++
- Program to find total sum of all substrings of a number given as string in Python
- Program to find out the sum of occurrences all possible substrings in a given string in python
- Program to find sum of beauty of all substrings in Python
- Program to count substrings with all 1s in binary string in Python
- Get all substrings of a string in JavaScript recursively
- Program to find total similarities of a string and its substrings in Python
- C++ Program to find minimal sum of all MEX of substrings
- How to List all Substrings in a given String using C#?
- Program to find out number of distinct substrings in a given string in python
- Program to find out the substrings of given strings at given positions in a set of all possible substrings in python
- Java program to find all duplicate characters in a string
- Python program to find all duplicate characters in a string
Advertisements