1138:将字符串中的小写字母转换成大写字母
时间: 2023-04-22 13:01:31 浏览: 120
可以使用Python内置函数upper()将字符串中的小写字母转换成大写字母。例如:
s = "Hello, World!"
s_upper = s.upper()
print(s_upper)
输出结果为:
HELLO, WORLD!
相关问题
13:将字符串中的小写字母转换成大写字母
可以使用Python中的upper()函数将字符串中的小写字母转换成大写字母。例如:
```
s = "Hello, World!"
s = s.upper()
print(s)
```
输出结果为:
```
HELLO, WORLD!
```
13:将字符串中的小写字母转换成大写字母c++
可以使用标准库函数 `toupper()` 将字符串中的小写字母转换成大写字母。下面是一个使用 `toupper()` 函数的示例代码:
```c++
#include <iostream>
#include <string>
#include <cctype>
int main() {
std::string str = "Hello, World!";
for (auto& c : str) {
if (std::islower(c)) {
c = std::toupper(c);
}
}
std::cout << str << std::endl;
return 0;
}
```
输出结果为:
```
HELLO, WORLD!
```
这里使用了 `std::islower()` 判断字符是否为小写字母,如果是,则使用 `std::toupper()` 函数将其转换成大写字母。循环遍历字符串中的所有字符,将所有的小写字母都转换成大写字母。
阅读全文
相关推荐















