
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to List all Substrings in a given String using C#?
To list all the substrings, use the Substring method and loop through the length of the string.
Let’s say our string is −
string myStr = "pqrz";
Use nested loop and get the substring in a new string −
for (int i = 1; i < myStr.Length; i++) { for (int start = 0; start <= myStr.Length - i; start++) { // get substrings } }
The following is the complete code −
Example
using System; public class Demo { public static void Main() { string myStr = "pqrz"; for (int i = 1; i < myStr.Length; i++) { for (int start = 0; start <= myStr.Length - i; start++) { string substr = myStr.Substring(start, i); Console.WriteLine(substr); } } } }
- Related Articles
- Find all substrings in a string using C#
- Program to print all substrings of a given string in C++
- Count Unique Characters of All Substrings of a Given String in C++
- C# Program to find all substrings in a string
- Program to find total sum of all substrings of a number given as string in Python
- Python - Find all the strings that are substrings to the given list of strings
- Get all substrings of a string in JavaScript recursively
- Program to find out the substrings of given strings at given positions in a set of all possible substrings in python
- Count the number of vowels occurring in all the substrings of given string in C++
- Program to find all substrings whose anagrams are present in a string in Python
- Program to count substrings with all 1s in binary string in Python
- Program to find out number of distinct substrings in a given string in python
- Program to sort all elements in a given list and merge them into a string in Python
- How to list all files in a directory using Java?
- Replacing Substrings in a Java String

Advertisements