.NET-如何将以“大写”分隔的字符串拆分为数组?

我如何从以下字符串开始:“ ThisIsMyCapsDelimitedString”


...到此字符串:“这是我的大写字母分隔字符串”


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


干杯!


白板的微信
浏览 796回答 3
3回答

幕布斯7119047

Regex.Replace("ThisIsMyCapsDelimitedString", "(\\B[A-Z])", " $1")

沧海一幻觉

只是有一点变化...这是一个不使用正则表达式的扩展方法。public static class CamelSpaceExtensions{&nbsp; &nbsp; public static string SpaceCamelCase(this String input)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; return new string(Enumerable.Concat(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; input.Take(1), // No space before initial cap&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InsertSpacesBeforeCaps(input.Skip(1))&nbsp; &nbsp; &nbsp; &nbsp; ).ToArray());&nbsp; &nbsp; }&nbsp; &nbsp; private static IEnumerable<char> InsertSpacesBeforeCaps(IEnumerable<char> input)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; foreach (char c in input)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (char.IsUpper(c))&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; yield return ' ';&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; yield return c;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP