大小写转换——islower/isupper或者tolwer/toupper函数的用法

简介: 大小写转换——islower/isupper或者tolwer/toupper函数的用法

大小写转换常用函数C++

islower/isupper函数

char ch1 = 'A';
char ch2 = 'b';

//使用islower函数判断字符是否为小写字母
if(islower(ch1)){
    cout << ch1 << "is a lowercase letter." << end1;
} else{
    cout << ch1 << "is not a lowercase letter." << end1;
}
//使用isupper函数判断字符是否为大写字母
if(isupper(ch2)){
    cout << ch2 << "is a uppercase letter." << end1;
} else{
    cout << ch2 << "is not a uppercase letter." << end1;
}

tolwer/toupper函数

char ch1 = 'A';
char ch2 = 'b';
//使用tolower函数将字符转换为小写字母
char lowercaseCh1 = tolwer(ch1);
cout << "tolower of" << ch1 << "is" << lowercaseCh1 << end1;

//使用toupper函数将字符转换为大写字母
char uppercaseCh2 = toupper(ch2);
cout << "uppercase of" << ch2 << "is" << uppercaseCh1<<end1;

实例

#include<bits/stdc++.h>
using namespace std;
char covertedCh(char ch){
  if(islower(ch)ch = toupper(ch));
  else if(isupper(ch)ch = tolower(ch));
}
int main()
{
    string s; getline(cin,s);
    for(auto &i : s)
        i = covertedCh(i);
    cout << s << end1;
    return 0;
}


相关文章
|
8月前
|
Python
Python函数isdigit()--判断字符串是否为数字
Python函数isdigit()--判断字符串是否为数字
123 0
|
5天前
|
存储 编译器 C语言
C++字符串大小写之for语句
C++字符串大小写之for语句
10 0
|
4月前
python-capitalize() 方法:将字符串的第一个字符转换为大写,其余字符转换为小写
python-capitalize() 方法:将字符串的第一个字符转换为大写,其余字符转换为小写
20 0
|
11月前
转换大小写与完成字符串反转
转换大小写与完成字符串反转
56 0
|
应用服务中间件 nginx C语言
大小写转换还能这样写?
大小写转换还能这样写?
118 1
大小写转换还能这样写?
字符串转换为大小写转换并且判断是否全为大小写
字符串转换为大小写转换并且判断是否全为大小写
字符串转换为大小写转换并且判断是否全为大小写
详解比较古怪的字符串拆分函数:strtok函数
详解比较古怪的字符串拆分函数:strtok函数
125 0
详解比较古怪的字符串拆分函数:strtok函数
利用for循环生成由ABCDEFG...XYZ,26个大写字母与26个小写字母组成的数组
利用for循环生成由ABCDEFG...XYZ,26个大写字母与26个小写字母组成的数组
385 0
|
C语言
总结C语言字符检测函数:isalnum、isalpha...
  前言:最近一直在刷leetcode的题,用到isalnum函数,用man手册查找了一下,总共有13个相关函数如下:   #include int isalnum(int c); int isalpha(int c); int isascii(int c); ...
1252 0