如何通过js将所有字符和大写字母仅包含在第一个字符中?(How to downcase all char and uppercase only the first characters via js?

编程入门 行业动态 更新时间:2024-10-28 13:13:39
如何通过js将所有字符和大写字母仅包含在第一个字符中?(How to downcase all char and uppercase only the first characters via js? [duplicate])

这个问题在这里已有答案:

如何在JavaScript中创建字符串大写的第一个字母? 75个答案

现在我有这个正则表达式: tSzoveg = tSzoveg.replace(/\b[AZ]{2,}\b/,'');

这几乎就是我想要的。 我想转换一下: THIS IS MINE, NOT YOURS. 对此: This is mine, not yours.

如何将其转换为正常句子?

This question already has an answer here:

How do I make the first letter of a string uppercase in JavaScript? 83 answers

Now I have this regex: tSzoveg = tSzoveg.replace(/\b[A-Z]{2,}\b/,'');

It is almost that I want. I want to convert this: THIS IS MINE, NOT YOURS. to this: This is mine, not yours.

How can I convert it to a normal sentence?

最满意答案

我会使用toLowerCase()然后修改第一个字母:

var str = "THIS IS MINE, NOT YOURS." str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();

I would use toLowerCase() and then modify the first letter:

var str = "THIS IS MINE, NOT YOURS." str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();

更多推荐

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

发布评论

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

>www.elefans.com

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