帕斯卡案例转换为一个句子的最佳方式 [英] Best way to convert Pascal Case to a sentence

查看:181
本文介绍了帕斯卡案例转换为一个句子的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是从Pascal大小写(上驼峰)转换为一个句子的最好方式。

例如开头

 AwaitingFeedback

和转换,为

 等待反馈

C#preferable,但我可以从Java或类似的转换。


解决方案

 公共静态字符串ToSentenceCase(此字符串str)
{
    返回Regex.Replace(STR[A-Z] [A-Z],M => m.Value [0] ++ char.ToLower(m.Value [1]));
}

在2015年后的Visual Studio版本中,你可以做

 公共静态字符串ToSentenceCase(此字符串str)
{
    返回Regex.Replace(STR[A-Z] [A-Z],M => ${m.Value [0]} {char.ToLower(m.Value [1])});
}

根据:从Pascal情况使用常规的前pression 句子

What is the best way to convert from Pascal Case (upper Camel Case) to a sentence.

For example starting with

"AwaitingFeedback"

and converting that to

"Awaiting feedback"

C# preferable but I could convert it from Java or similar.

解决方案

public static string ToSentenceCase(this string str)
{
    return Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + " " + char.ToLower(m.Value[1]));
}

In versions of visual studio after 2015, you can do

public static string ToSentenceCase(this string str)
{
    return Regex.Replace(str, "[a-z][A-Z]", m => $"{m.Value[0]} {char.ToLower(m.Value[1])}");
}

Based on: Converting Pascal case to sentences using regular expression

这篇关于帕斯卡案例转换为一个句子的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆