将字符转换为大写 [英] Convert a char to upper case

查看:52
本文介绍了将字符转换为大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含单个 char 的变量.我想将此 char 转换为大写.但是,to_uppercase 函数返回一个 rustc_unicode::char::ToUppercase 结构而不是 char.

I have a variable which contains a single char. I want to convert this char to upper case. However, the to_uppercase function returns a rustc_unicode::char::ToUppercase struct instead of a char.

推荐答案

ToUppercase 是一个迭代器,因为大写版本的字符可能由几个代码点组成,正如 delnan 在评论中指出的那样.您可以将其转换为字符向量:

ToUppercase is an iterator, because the uppercase version of the character may be composed of several codepoints, as delnan pointed in the comments. You can convert that to a Vector of characters:

c.to_uppercase().collect::<Vec<_>>();

然后,您应该按照 ker 的指示将这些字符收集到一个字符串中.

Then, you should collect those characters into a string, as ker pointed.

这篇关于将字符转换为大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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