本文介绍了.NET - 如何拆分“大写"?分隔字符串到数组中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从这个字符串开始:ThisIsMyCapsDelimitedString"

How do I go from this string: "ThisIsMyCapsDelimitedString"

...到这个字符串:这是我的大写分隔字符串"

...to this string: "This Is My Caps Delimited String"

最好使用 VB.net 中最少的代码行,但也欢迎使用 C#.

Fewest lines of code in VB.net is preferred but C# is also welcome.

干杯!

推荐答案

我不久前做了这个.它匹配 CamelCase 名称的每个组成部分.

I made this a while ago. It matches each component of a CamelCase name.

/([A-Z]+(?=$|[A-Z][a-z])|[A-Z]?[a-z]+)/g

例如:

"SimpleHTTPServer" => ["Simple", "HTTP", "Server"]
"camelCase" => ["camel", "Case"]

要将其转换为仅在单词之间插入空格:

To convert that to just insert spaces between the words:

Regex.Replace(s, "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 ")

如果您需要处理数字:


If you need to handle digits:

/([A-Z]+(?=$|[A-Z][a-z]|[0-9])|[A-Z]?[a-z]+|[0-9]+)/g

Regex.Replace(s,"([a-z](?=[A-Z]|[0-9])|[A-Z](?=[A-Z][a-z]|[0-9])|[0-9](?=[^0-9]))","$1 ")

这篇关于.NET - 如何拆分“大写"?分隔字符串到数组中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 07:25
查看更多