_strlwr_s、_strlwr_s_l、_mbslwr_s、_mbslwr_s_l、_wcslwr_s、_wcslwr_s_l_strlwr_s, _strlwr_s_l, _mbslwr_s, _mbslwr_s_l, _wcslwr_s, _wcslwr_s_l

通过使用当前区域设置或传递的区域设置对象将字符串转换为小写。Converts a string to lowercase, by using the current locale or a locale object that's passed in. CRT 的安全性增强功能中所述,这些版本的 _strlwr、_wcslwr, _mbslwr、_strlwr_l、_wcslwr_l、_mbslwr_l 具有安全性增强功能。These versions of _strlwr, _wcslwr, _mbslwr, _strlwr_l, _wcslwr_l, _mbslwr_l have security enhancements, as described in Security Features in the CRT.

重要

_mbslwr_s_mbslwr_s_l不能用于在 Windows 运行时中执行的应用程序。_mbslwr_s and _mbslwr_s_l cannot be used in applications that execute in the Windows Runtime. 有关详细信息,请参阅通用 Windows 平台应用中不支持的 CRT 函数For more information, see CRT functions not supported in Universal Windows Platform apps.

语法Syntax

errno_t _strlwr_s(
   char *str,
   size_t numberOfElements
);
errno_t _strlwr_s_l(
   char *str,
   size_t numberOfElements,
   _locale_t locale
);
errno_t _mbslwr_s(
   unsigned char *str,
   size_t numberOfElements
);
errno_t _mbslwr_s_l(
   unsigned char *str,
   size_t numberOfElements,
   _locale_t locale
);
errno_t _wcslwr_s(
   wchar_t *str,
   size_t numberOfElements
);
errno_t _wcslwr_s_l(
   wchar_t *str,
   size_t numberOfElements,
   _locale_t locale
);
template <size_t size>
errno_t _strlwr_s(
   char (&str)[size]
); // C++ only
template <size_t size>
errno_t _strlwr_s_l(
   char (&str)[size],
   _locale_t locale
); // C++ only
template <size_t size>
errno_t _mbslwr_s(
   unsigned char (&str)[size]
); // C++ only
template <size_t size>
errno_t _mbslwr_s_l(
   unsigned char (&str)[size],
   _locale_t locale
); // C++ only
template <size_t size>
errno_t _wcslwr_s(
   wchar_t (&str)[size]
); // C++ only
template <size_t size>
errno_t _wcslwr_s_l(
   wchar_t (&str)[size],
   _locale_t locale
); // C++ only

参数Parameters

strstr
null 终止的字符串转换为小写。Null-terminated string to convert to lowercase.

numberOfElementsnumberOfElements
缓冲区的大小。Size of the buffer.

localelocale
要使用的区域设置。The locale to use.

返回值Return Value

如果成功,则返回零;如果失败,则返回非零错误代码。Zero if successful; a non-zero error code on failure.

这些函数验证其参数。These functions validate their parameters. 如果str不是有效的 null 终止字符串,则调用无效参数处理程序,如中所述参数验证If str is not a valid null-terminated string, the invalid parameter handler is invoked, as described in Parameter Validation . 如果允许执行继续,函数将返回EINVAL并设置errnoEINVALIf execution is allowed to continue, the functions return EINVAL and set errno to EINVAL. 如果numberOfElements是字符串的长度小于函数还返回EINVAL并设置errnoEINVALIf numberOfElements is less than the length of the string, the functions also return EINVAL and set errno to EINVAL.

备注Remarks

_Strlwr_s函数将转换时,就地情况下,任何大写字母中str为小写形式。The _strlwr_s function converts, in place, any uppercase letters in str to lowercase. _mbslwr_s是多字节字符版本的 _strlwr_s_mbslwr_s is a multi-byte character version of _strlwr_s. _wcslwr_s是宽字符版本的 _strlwr_s_wcslwr_s is a wide-character version of _strlwr_s.

输出值受区域设置的 LC_CTYPE 类别设置影响;有关详细信息,请参阅 setlocaleThe output value is affected by the setting of the LC_CTYPE category setting of the locale; see setlocale for more information. 这些不带 _l 后缀的函数版本使用此区域设置相关的行为的当前区域设置;带有 _l 后缀的版本相同,只不过它们使用传递的区域设置参数。The versions of these functions without the _l suffix use the current locale for this locale-dependent behavior; the versions with the _l suffix are identical except that they use the locale parameter passed in instead. 有关详细信息,请参阅 LocaleFor more information, see Locale.

在 C++ 中,使用这些函数由模板重载简化;重载可以自动推导出缓冲区长度 (不再需要指定大小自变量),并且它们可以自动用以更新、更安全的对应物替换旧的、不安全的函数。In C++, using these functions is simplified by template overloads; the overloads can infer buffer length automatically (eliminating the need to specify a size argument) and they can automatically replace older, non-secure functions with their newer, secure counterparts. 有关详细信息,请参阅 Secure Template OverloadsFor more information, see Secure Template Overloads.

这些函数的调试版本首先用 0xFD 填充缓冲区。The debug versions of these functions first fill the buffer with 0xFD. 若要禁用此行为,请使用 _CrtSetDebugFillThresholdTo disable this behavior, use _CrtSetDebugFillThreshold.

一般文本例程映射Generic-Text Routine Mappings

TCHAR.H 例程TCHAR.H routine 未定义 _UNICODE 和 _MBCS_UNICODE & _MBCS not defined 已定义 _MBCS_MBCS defined 已定义 _UNICODE_UNICODE defined
_tcslwr_s_tcslwr_s _strlwr_s_strlwr_s _mbslwr_s_mbslwr_s _wcslwr_s_wcslwr_s
_tcslwr_s_l_tcslwr_s_l _strlwr_s_l_strlwr_s_l _mbslwr_s_l_mbslwr_s_l _wcslwr_s_l_wcslwr_s_l

要求Requirements

例程Routine 必需的标头Required header
_strlwr_s_strlwr_s_l_strlwr_s, _strlwr_s_l <string.h><string.h>
_mbslwr_s_mbslwr_s_l_mbslwr_s, _mbslwr_s_l <mbstring.h><mbstring.h>
_wcslwr_s_wcslwr_s_l_wcslwr_s, _wcslwr_s_l <string.h> 或 <wchar.h><string.h> or <wchar.h>

有关其他兼容性信息,请参阅 兼容性For additional compatibility information, see Compatibility.

示例Example

// crt_strlwr_s.cpp
// This program uses _strlwr_s and _strupr_s to create
// uppercase and lowercase copies of a mixed-case string.
//

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
   char str[] = "The String to End All Strings!";
   char *copy1, *copy2;
   errno_t err;

   err = _strlwr_s( copy1 = _strdup(str), strlen(str) + 1);
   err = _strupr_s( copy2 = _strdup(str), strlen(str) + 1);

   printf( "Mixed: %s\n", str );
   printf( "Lower: %s\n", copy1 );
   printf( "Upper: %s\n", copy2 );

   free( copy1 );
   free( copy2 );

   return 0;
}
Mixed: The String to End All Strings!
Lower: the string to end all strings!
Upper: THE STRING TO END ALL STRINGS!

请参阅See also

字符串操作String Manipulation
区域设置Locale
多字节字符序列的解释Interpretation of Multibyte-Character Sequences
_strupr_s、_strupr_s_l、_mbsupr_s、_mbsupr_s_l、_wcsupr_s、_wcsupr_s_l_strupr_s, _strupr_s_l, _mbsupr_s, _mbsupr_s_l, _wcsupr_s, _wcsupr_s_l