C语言中如何将字符串小写?
在 C 中如何将混合大小写字符串转换为小写字符串?
How can I convert a mixed case string to a lowercase string in C?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
在 C 中如何将混合大小写字符串转换为小写字符串?
How can I convert a mixed case string to a lowercase string in C?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
它位于标准库中,这是我所看到的实现此类功能的最直接的方法。所以是的,只需循环字符串并将每个字符转换为小写即可。
像这样的小事:
或者如果您更喜欢一种衬垫,那么您可以使用 JF Sebastian 的这款:
It's in the standard library, and that's the most straight forward way I can see to implement such a function. So yes, just loop through the string and convert each character to lowercase.
Something trivial like this:
or if you prefer one liners, then you can use this one by J.F. Sebastian:
如果您将自己限制为 ASCII,则转换为小写相当于上升位 0x60:
to convert to lower case is equivalent to rise bit 0x60 if you restrict yourself to ASCII:
循环指针以获得更好的性能:
Looping the pointer to gain better performance:
如果我们要像使用 tolower() 一样草率,请执行以下操作:
但是,好吧,如果您向它提供一些符号/数字,它就会爆炸,并且通常它是邪恶的。不过,面试问题很好。
If we're going to be as sloppy as to use
tolower()
, do this:But, well, it kinda explodes if you feed it some symbols/numerals, and in general it's evil. Good interview question, though.
我是 C 新手,一直在努力将字符串从大写转换为小写。我错误地更改了字符串 'A' + 32 = 'a'。而且我无法解决这个问题。
我使用了 char 类型,最后我能够将其转换为 string 类型。您可以咨询:
I'm new to C and have been trying hard to convert strings from uppercase to lowercase. I made the mistake of changing the string 'A' + 32 = 'a'. And I can't solve the problem.
I used char type and finally I was able to convert it to string type. You can consult:
您可以使用这个用户定义的函数:
You may use this user defined function: