可能重复: 算法来QUOT&; spacify"驼峰格式字符串
我有一个这样的字符串: MyUnsolvedProblem
我要修改字符串是这样的:我的尚未解决的问题
我怎么能这样做?我曾尝试使用正则表达式,没有运气!
解决方案 VAR的结果= Regex.Replace(MyUnsolvedProblem,@(\ p {鲁}),$ 1 ).TrimStart();
没有正则表达式:
VAR S =MyUnsolvedProblem;
VAR的结果= string.Concat(s.Select(C => char.IsUpper(三)+ c.ToString():c.ToString()))
.TrimStart();
Possible Duplicate: An algorithm to "spacify" CamelCased strings
I have a string like this: MyUnsolvedProblem
I want to modify the string like this: My Unsolved Problem
How can I do that? I have tried using Regex with no luck!
解决方案var result = Regex.Replace("MyUnsolvedProblem", @"(\p{Lu})", " $1").TrimStart();
Without regex:
var s = "MyUnsolvedProblem";
var result = string.Concat(s.Select(c => char.IsUpper(c) ? " " + c.ToString() : c.ToString()))
.TrimStart();