仅将字符串的首字母大写

编程入门 行业动态 更新时间:2024-10-24 15:26:05
本文介绍了仅将字符串的首字母大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经看过这样的帖子了:

I have already taken a look at such posts like:

格式化为首字母大写 如何大写每个字母的首字母字符串中的单词

但是这些似乎都不起作用.我首先想到的是:

But none of these seem to actually work. I would of thought to start with that there would just be a:

.Capitalize();

就像那里一样:

.Lower(); & .Upper();

有人可以给我有关转换为类似字符串的任何文档或参考吗?

Could anyone possibly give me any documentation or references regarding converting to a string like:

string before = "INVOICE";

然后成为:

string after = "Invoice";

我使用我所阅读的帖子解决方案给我的方式没有收到任何错误,但是,之前仍然保持为大写.

I receive no errors using the way the posts solutions I read give me, however, the before still remains Capitalized.

推荐答案

在第一个字符上使用 ToUpper ,在其余字符串上使用 ToLower 怎么样?

What about using ToUpper on the first char and ToLower on the remaining string?

string after = char.ToUpper(before.First()) + before.Substring(1).ToLower();

更多推荐

仅将字符串的首字母大写

本文发布于:2023-10-16 05:57:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496688.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   首字母

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!