- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Articles
- Find all substrings in a string using C#
- Program to print all substrings of a given string in C++
- Program to find all substrings whose anagrams are present in a string in Python
- How to List all Substrings in a given String using C#?
- Program to find total sum of all substrings of a number given as string in Python
- C++ Program to find minimal sum of all MEX of substrings
- Program to count substrings with all 1s in binary string in Python
- Program to find sum of beauty of all substrings in Python
- Program to find total similarities of a string and its substrings in Python
- Count Unique Characters of All Substrings of a Given String in C++
- Get all substrings of a string in JavaScript recursively
- 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
- Find the Number of Substrings of a String using C++
- Program to find split a string into the max number of unique substrings in Python

Advertisements