tolower

来自cppreference.com
< c‎ | string‎ | byte
在标头 <ctype.h> 定义
int tolower( int ch );

按照当前安装的 C 本地环境所定义的规则,转换给定字符为小写。

默认 "C" 本地环境中,以相应的小写字母 abcdefghijklmnopqrstuvwxyz 替换大写字母 ABCDEFGHIJKLMNOPQRSTUVWXYZ

目录

[编辑] 参数

ch - 要转换的字符。若 ch 的值不能表示为 unsigned char 且不等于 EOF,则行为未定义。

[编辑] 返回值

ch 的小写版本,或若当前 C 本地环境中无小写版本,则返回不修改的 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("在 iso8859-1 中,tolower('0x%x') 得到 0x%x\n", c, tolower(c));
    setlocale(LC_ALL, "en_US.iso885915");
    printf("在 iso8859-15 中,tolower('0x%x') 得到 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
 
在 iso8859-1 中,tolower('0xb4') 得到 0xb4
在 iso8859-15 中,tolower('0xb4') 得到 0xb8

[编辑] 引用

  • C23 标准(ISO/IEC 9899:2024):
  • 7.4.2.1 The tolower function (第 TBD 页)
  • C17 标准(ISO/IEC 9899:2018):
  • 7.4.2.1 The tolower function (第 147 页)
  • C11 标准(ISO/IEC 9899:2011):
  • 7.4.2.1 The tolower function (第 203 页)
  • C99 标准(ISO/IEC 9899:1999):
  • 7.4.2.1 The tolower function (第 184 页)
  • C89/C90 标准(ISO/IEC 9899:1990):
  • 4.3.2.1 The tolower function

[编辑] 参阅

将字符转换成大写
(函数) [编辑]
转换宽字符为小写
(函数) [编辑]
tolower 的 C++ 文档