Home >Backend Development >C++ >How Can I Split a String in C# Using Multi-Character Delimiters?
Split string in C# using multi-character delimiter
In some cases it may be necessary to split a string using a delimiter containing multiple characters. This question focuses on how to accomplish this task in C#.
The solution lies in utilizing the Split() method provided by the System.String class. This method allows specifying an array of strings as delimiters. For example, to split the string "This is a sentence." by the word "is", you can define the following code:
<code class="language-c#">string source = "This is a sentence."; string[] delimiters = new string[] { "is" }; string[] result = source.Split(delimiters, StringSplitOptions.None);</code>
The generated result array will contain two elements: "This" and "a sentence."
The MSDN documentation provides details and examples on using the Split() method: https://www.php.cn/link/bb8c2a522653f0e10c557d9e7cd18784.
The above is the detailed content of How Can I Split a String in C# Using Multi-Character Delimiters?. For more information, please follow other related articles on the PHP Chinese website!