C# split string based on 1 or more spaces

黄舟
Release: 2017-03-01 10:29:19
Original
2545 people have browsed it

Example scenario, for the string: "AAAA AAA BBBB BBB BBB CCCCCCCC".

1. Separated as "AAAA AAA", "BBBB BBB BBB", "CCCCCCCC"

2. Separated as "AAAA", "AAA", "BBBB", "BBB", "BBB", "CCCCCCCC"

Implementation code:

void Main()
{
	var str = "AAAA AAA        BBBB BBB BBB        CCCCCCCC";
	
	// - split by multiple spaces(more than one)
	var val = System.Text.RegularExpressions.Regex.Split( str, @"\s{2,}");
	System.Console.WriteLine(val);
	
	// - split by spaces(one or more)
	var val2 = System.Text.RegularExpressions.Regex.Split( str, @"\s{1,}");
	System.Console.WriteLine(val2);
}
Copy after login

The above is the content of C# split string according to 1 or more spaces. For more related content, please pay attention to the PHP Chinese website (www .php.cn)!


Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!