
- 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
Find all substrings in a string using C#
Use the substring() method in C# to find all substrings in a string.
Let’s say our string is −
pqr
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); }
The following is the C# program to find all substrings in a string −
Example
using System; class Demo { static void Main() { string str = "pqr"; 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
p q r pq qr
- Related Articles
- C# Program to find all substrings in a string
- How to List all Substrings in a given String using C#?
- Get all substrings of a string in JavaScript recursively
- Find the Number of Substrings of 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++
- Find distinct characters in distinct substrings of a string
- Program to find total sum of all substrings of a number given as string in Python
- Count Unique Characters of All Substrings of a Given String in C++
- Find substrings that contain all vowels in Python
- Find all substrings combinations within arrays in JavaScript
- Find the Number of Substrings of One String Present in Other using C++
- Replacing Substrings in a Java String
- Program to count substrings with all 1s in binary string in Python
- Find All Duplicate Characters from a String using Python

Advertisements