Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
C# | ToCharArray() Method
Next article icon

C# String Split() Method

Last Updated : 26 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In C#, Split() is a string class method used to divide a string into an array of substrings. The Split() method divides a string into an array of substrings using specified delimiters.

The delimiters can be:

  • A character for example comma(,) or underscore(-).
  • An array of characters char[] or an array of strings string[].

In simple words, it returns a string array that contains the substrings in the current instance that are delimited by elements of a specified string or Unicode character array.

Example: Separating a string based on space using String.Split() method.

C#
// C# program to illustrate the // String.Split() Method  using System;  class Geeks {  	public static void Main() 	{ 		// declaring the string 		String str = "Hello from GeeksforGeeks";  		// Splitting the string 		// into substrings separated by spaces 		string[] split = str.Split(' ');  		foreach (var word in split) 		{    			Console.WriteLine(word); 		} 	} } 

Output
Hello from GeeksforGeeks 

Explanation: In the above example, we use the Split() method which converts the string into the string array based on a single space and then we print each string present in the array using the foreach loop.

Different Overloads of String.Split() Method

These are the six overloads of String.Split() method.

MethodsDescription
Split(String[], Int32, StringSplitOptions)Split string into a maximum number of sub-strings based on the array of strings passed as parameters. We can specify whether to include the empty array elements in an array of substrings or not.
Split(Char[], Int32, StringSplitOptions)Split string into a maximum number of sub-strings based on the array of characters passed as a parameter. We can specify whether to include the empty array elements in an array of substrings or not.
Split(String[], StringSplitOptions)Splits a string into substrings based on the array of strings. We can specify whether to include the empty array elements in an array of substrings or not.
Split(Char[])Splits a string into substrings based on the array of characters.
Split(Char[], StringSplitOptions)Splits a string into substrings based on the array of characters. We can specify whether to include the empty array elements in an array of substrings or not.
Split(Char[], Int32)Split string into a maximum number of sub-strings based on the array of characters passed as a parameter. We can specify a maximum number of sub-strings to return.

Parameters:

  • separator: It is a character or a set of characters or an array of string[] that defines the points at which a string should be split into substrings
  • options: RemoveEmptyEntries or None option to omit empty array elements from the array returned or None option to include empty array elements in the array returned.
  • count: It defines the maximum number of substrings to return. If omitted, all possible substrings are returned.

Return Type: This method returns an array whose elements contain the substrings in this string which are delimited by one or more characters or an array of strings in the separator .

Exceptions:

  • ArgumentOutOfRangeException: If the count is negative.
  • ArgumentException: If the options are not one of the StringSplitsOptions values.

1. Split(String[], Int32, StringSplitOptions)

This method is used to split a string into a maximum number of substrings based on the strings in an array. We can specify whether the substrings include empty array elements or not.

Syntax:

public String[] Split(String[] separator, int count, StringSplitOptions options);

Example: Separate the string using the Split(String[], Int32, StringSplitOptions) method.

C#
// C# program to illustrate Split(String[], Int32, StringSplitOptions) using System;   class Geeks  {      static void Main(string[] args)      {         // Declaring the string          string s = "Geeks, For Geeks";           // String array of separators         string[] sp = { ",", "For" };           // Count of substrings to be returned         int c = 2;           // Splitting the string         string[] strlist = s.Split(sp, c, StringSplitOptions.RemoveEmptyEntries);           // Displaying the substrings         foreach(string str in strlist)          {              Console.WriteLine(str);          }      }  } 

Output
Geeks  For Geeks 


2. Split(Char[], Int32, StringSplitOptions)

This method is used to split a string into a maximum number of substrings based on the characters in an array passed on the argument and also we can pass the count of the maximum substring to return.

Syntax:

public String[] Split(char[] separator, int count, StringSplitOptions options);

Example:

C#
// C# program to illustrate the  // Split(Char[], Int32,  // StringSplitOptions) Method  using System;   class Geeks {     static void Main(string[] args)  	{ 		// Taking a string  		String str = "Geeks, For Geeks";   		// Array of spliters  		char[] sp = { ',', ' ' };   		// Count of substrings 		// to be returned 		Int32 c = 2;   		// Using the split method 		// with StringSplitOptions.None 		String[] list = str.Split(sp,  		c, StringSplitOptions.None);   		foreach(String s in list) 			Console.WriteLine(s); 	}  }  

Output
Geeks  For Geeks 


3. Split(String[], StringSplitOptions)

This method is used to split a string into substrings based on the strings in an array. We can also specify whether the substrings include empty array elements or not.

Syntax:

public String[] Split(String[] separator, StringSplitOptions options);

Example:

C#
// C# program to illustrate the  // Split(String[], StringSplitOptions) Method  using System;   class Geeks {       static void Main(string[] args)      {          // Declaring and initializing the string         String str = "Geeks,For Geeks";          // Array of separators          String[] sp = { ",", " " };           // Splitting the string         String[] list = str.Split(sp, StringSplitOptions.None);           foreach(String s in list)          {              Console.WriteLine(s);          }      }  }  

Output
Geeks For Geeks 


4. Split(char[])

This method is used to split a string into a maximum number of substrings based on the characters in an array. We can also specify the maximum number of substrings to return.

Syntax:

public String[] Split(char[] separator);

Example:

C#
// C# program to illustrate the  // Split(Char[]) Method   using System;   class Geeks  {      static void Main(string[] args)      {          // Declaring and initializing the string         String str = "Geeks,For Geeks";                   // Character array of separator         // to split the string         char[] separator = { ',', ' ' };                   // Using the split method         String[] strlist = str.Split(separator);                   foreach(String s in strlist)          {              Console.WriteLine(s);          }      }  }  

Output
Geeks For Geeks 


5. Split(char[], StringSplitOptions )

This method splits a string into substrings based on the characters in an array passed as a separator. We can also specify whether empty array elements should be included or not using the second parameter StringSplitOptions.

Syntax:

public String[] Split(char[] separator, StringSplitOptions option);

Example:

C#
// C# program to illustrate the use of  // Split(Char[], StringSplitOptions) method  using System;     class Geeks {      static void Main(string[] args)      {         String s = "Geeks, For Geeks";                   // Character array as          // As a separator         char[] sp = { ',', ' ' };             // Using the method          String[] list = s.Split(sp,           StringSplitOptions.RemoveEmptyEntries);             foreach(String i in list)          {              Console.WriteLine(i);          }      }  }  

Output
Geeks For Geeks 


6. Split(Char[], Int32)

This method is used to splits the string into a maximum number of substrings based on the characters in an array passed as a seperator. We can also specify the maximum number of substrings which we want to return.

public String[] Split(char[] separator, int count);

Example:

C#
// C# program to illustrate Split(Char[], Int32) using System;   class Geeks  {      static void Main(string[] args)      {          // Declaring and initializing the string         string s = "Geeks,For Geeks";                   // Character array of separators         char[] sp = { ',', ' ' };                   // Using the split method         string[] list = s.Split(sp, 3);                   foreach(string i in list)          {              Console.WriteLine(i);          }      }  } 

Output
Geeks For Geeks 


Next Article
C# | ToCharArray() Method

P

ParthManiyar
Improve
Article Tags :
  • C#
  • CSharp-method
  • CSharp-string

Similar Reads

  • C# | Substring() Method
    In C#, Substring() is a string method. It is used to retrieve a substring from the current instance of the string. This method can be overloaded by passing the different number of parameters to it as follows: String.Substring(Int32) Method String.Substring(Int32, Int32) Method String.Substring Metho
    3 min read
  • C# String Remove() Method
    In C#, the Remove() method of the String class is used for removing the characters from the specified position of a string. If the length is not specified, then it will remove all the characters after the specified position. This method can be overloaded by changing the number of arguments passed to
    3 min read
  • C# | TrimStart() and TrimEnd() Method
    Prerequisite: Trim() Method in C# In C#, TrimStart() & TrimEnd() are the string methods. TrimStart() method is used to remove the occurrences of a set of characters specified in an array from the starting of the current String object. TrimEnd() method is used to remove the occurrences of a set o
    3 min read
  • C# | ToCharArray() Method
    In C#, ToCharArray() is a string method. This method is used to copy the characters from a specified string in the current instance to a Unicode character array or the characters of a specified substring in the current instance to a Unicode character array. This method can be overloaded by changing
    4 min read
  • C# Program For Counting Lines in a String
    In C#, a string is a sequence of Unicode characters or an array of characters. The range of Unicode characters will be U+0000 to U+FFFF. A string is the representation of the text. In this article, we will create a C# program that will count the lines present in the given string. Example: Input : he
    6 min read
  • C# StringBuilder
    StringBuilder is a Dynamic Object. It doesn’t create a new object in the memory but dynamically expands the needed memory to accommodate the modified or new string.A String object is immutable, i.e. a String cannot be changed once created. To avoid string replacing, appending, removing or inserting
    4 min read
  • C# - Different Ways to Find All Substrings in a String
    Given a string as an input we need to find all the substrings present in the given string. Example: Input: geeks Output: g e e k s ge ee ek ks gee eek eks geek eeks geeks Input: ab Output: a b abMethod 1: Using Substring() method We can find all the substrings from the given string using the Substri
    3 min read
  • C# | Char.IsSeparator ( ) Method
    In C#, Char.IsSeparator() is a System.Char struct method which is used to check whether a Unicode character can be categorized as a separator character or not. This method can be overloaded by passing different type and number of arguments to it. Char.IsSeparator(Char) MethodChar.IsSeparator(String,
    3 min read
  • How to Split a String by a Delimiter in C?
    Splitting a string by a delimiter is a common task in programming. In C, strings are arrays of characters, and there are several ways to split them based on a delimiter. In this article, we will explore different methods to split a string by a delimiter in C. Splitting Strings in CThe strtok() metho
    2 min read
  • Convert String to int in C
    In C, we cannot directly perform numeric operations on a string representing a numeric value. We first need to convert the string to the integer type. In this article, we will discuss different ways to convert the numeric string to integer in C language. Example: Input: "1234"Output: 1234Explanation
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences