Home > Backend Development > C++ > How to Split Strings by Substrings in C#?

How to Split Strings by Substrings in C#?

Linda Hamilton
Release: 2025-01-23 19:36:10
Original
488 people have browsed it

How to Split Strings by Substrings in C#?

Split string using substring in C#

While the Split() method is typically used to split strings based on a single character, it is also possible to split strings using longer substrings.

Solution:

To split a string by a specific substring, use the string array overload of the Split() method. Here's an example:

<code class="language-csharp">string data = "THExxQUICKxxBROWNxxFOX";
string splitter = "xx";

string[] splitResult = data.Split(new string[] { splitter }, StringSplitOptions.None);</code>
Copy after login

This code will return an array containing the following values:

<code>["THE", "QUICK", "BROWN", "FOX"]</code>
Copy after login

Instructions:

In the string array overload of Split(), the first parameter represents the substring array to be split. In this example, we create an array containing the delimiter string and pass it as a parameter.

The

StringSplitOptions.None parameter specifies that splitting should be done based on the entire delimiter substring, not on any of its characters.

The above is the detailed content of How to Split Strings by Substrings in C#?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template