_strlwr_s, _strlwr_s_l, _mbslwr_s, _mbslwr_s_l, _wcslwr_s, _wcslwr_s_l
Convert a string to lowercase, using the current locale or a locale object passed in. These are versions of _strlwr, _wcslwr, _mbslwr, _strlwr_l, _wcslwr_l, _mbslwr_l with security enhancements as described in Security Enhancements in the CRT.
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
- str
-
Null-terminated string to convert to lowercase.
- numberOfElements
-
Size of the buffer.
- locale
-
The locale to use.
Zero if successful; a non-zero error code on failure.
These functions validate their parameters. If str is a NULL pointer, the invalid parameter handler is invoked, as described in Parameter Validation . If execution is allowed to continue, the functions return EINVAL and set errno to EINVAL. If numberOfElements is less than the length of the string, the functions return ERANGE and set errno to ERANGE.
The _strlwr_s function converts, in place, any uppercase letters in str to lowercase. _mbslwr_s is a multi-byte character version of _strlwr_s. _wcslwr_s is a wide-character version of _strlwr_s.
The output value is affected by the setting of the LC_CTYPE category setting of the locale; see setlocale for more information. 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.
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. For more information, see Secure Template Overloads.
The debug versions of these functions first fill the buffer with 0xFD. To disable this behavior, use _CrtSetDebugFillThreshold.
| TCHAR.H routine | _UNICODE & _MBCS not defined | _MBCS defined | _UNICODE defined |
|---|---|---|---|
| _tcslwr_s | _strlwr_s | _mbslwr_s | _wcslwr_s |
| _tcslwr_s_l | _strlwr_s_l | _mbslwr_s_l | _wcslwr_s_l |
| Routine | Required header | Compatibility |
|---|---|---|
| _strlwr_s, _strlwr_s_l | <string.h> | Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 |
| _mbslwr_s, _mbslwr_s_l | <string.h> or <wchar.h> | Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 |
| _wcslwr_s, _wcslwr_s_l | <string.h> or <wchar.h> | Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 |
For additional compatibility information, see Compatibility in the Introduction.
// crt_strlwr_s.c
// 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>
int main( void )
{
char string[100] = "The String to End All Strings!";
char *copy1, *copy2;
errno_t err;
err = _strlwr_s( copy1 = _strdup(string), 100);
err = _strupr_s( copy2 = _strdup(string), 100);
printf( "Mixed: %s\n", string );
printf( "Lower: %s\n", copy1 );
printf( "Upper: %s\n", copy2 );
free( copy1 );
free( copy2 );
}
Output
Mixed: The String to End All Strings! Lower: the string to end all strings! Upper: THE STRING TO END ALL STRINGS!