tolower
From cppreference.net
|
定义于头文件
<ctype.h>
|
||
|
int
tolower
(
int
ch
)
;
|
||
根据当前安装的C语言区域设置定义的字符转换规则,将给定字符转换为小写形式。
在默认的 "C" 语言环境中,以下大写字母
ABCDEFGHIJKLMNOPQRSTUVWXYZ
会被替换为对应的小写字母
abcdefghijklmnopqrstuvwxyz
。
目录 |
参数
| ch | - | 待转换的字符。如果 ch 的值无法表示为 unsigned char 且不等于 EOF ,则行为未定义。 |
返回值
当前 C 本地环境中 ch 的小写版本,若未列出小写形式则返回原值 ch 。
示例
运行此代码
#include <ctype.h> #include <limits.h> #include <locale.h> #include <stdio.h> int main(void) { // 在默认区域设置中 for (unsigned char u = 0; u < UCHAR_MAX; u++) { unsigned char l = tolower(u); if (l != u) printf("%c%c ", u, l); } printf("\n\n"); unsigned char c = '\xb4'; // 该字符在 ISO-8859-15 中表示 Ž // 在 ISO-8859-1 中表示 ´(锐音符) setlocale(LC_ALL, "en_US.iso88591"); printf("in iso8859-1, tolower('0x%x') gives 0x%x\n", c, tolower(c)); setlocale(LC_ALL, "en_US.iso885915"); printf("in iso8859-15, tolower('0x%x') gives 0x%x\n", c, tolower(c)); }
可能的输出:
Aa Bb Cc Dd Ee Ff Gg Hh Ii Jj Kk Ll Mm Nn Oo Pp Qq Rr Ss Tt Uu Vv Ww Xx Yy Zz
in iso8859-1, tolower('0xb4') gives 0xb4
in iso8859-15, tolower('0xb4') gives 0xb8
参考文献
- C23 标准 (ISO/IEC 9899:2024):
-
- 7.4.2.1 tolower 函数 (p: TBD)
- C17 标准 (ISO/IEC 9899:2018):
-
- 7.4.2.1 tolower 函数 (p: 147)
- C11 标准 (ISO/IEC 9899:2011):
-
- 7.4.2.1 tolower 函数 (p: 203)
- C99标准(ISO/IEC 9899:1999):
-
- 7.4.2.1 tolower函数(页码:184)
- C89/C90 标准 (ISO/IEC 9899:1990):
-
- 4.3.2.1 tolower 函数
参见
|
将字符转换为大写形式
(函数) |
|
|
(C95)
|
将宽字符转换为小写形式
(函数) |
|
C++ documentation
for
tolower
|
|