获取大写字母索引从字符串 [英] Get the Index of Upper Case letter from a String
本文介绍了获取大写字母索引从字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的字符串: 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();
这篇关于获取大写字母索引从字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文