获取大写字母索引从字符串大写字母、字符串、索引

2023-09-05 01:28:43 作者:你的名字,我的心事

可能重复:   算法来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();
 

java 作业一,计算一个字符串中大写字母和小写字母还有数字的数量

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();