Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一个字符串:
"Joe Doe is not here"
我想仅在包含多个空格的情况下拆分此字符串,但将 Joe Doe 保留为一个子字符串。
所以结果将是:
string[] result={"Joe Doe","is","not","Here"}
使用带有 @"\s{2,}" 作为模式的 Regex.Split - 将在有 2 个或更多空白字符的地方进行拆分。
Regex.Split(input, @"\s{2,}")
这个正则表达式需要最少。2个空格。