다음을 통해 공유


_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.

Return Value

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.

Remarks

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. For more information, see Locale.

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.

Generic-Text Routine Mappings

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

Requirements

Routine

Required header

_strlwr_s, _strlwr_s_l

<string.h>

_mbslwr_s, _mbslwr_s_l

<string.h> or <wchar.h>

_wcslwr_s, _wcslwr_s_l

<string.h> or <wchar.h>

For additional compatibility information, see Compatibility in the Introduction.

Example

// 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 );
}

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

.NET Framework Equivalent

System::String::ToLower

Smart Device Developer Notes

These methods are provided for Windows CE; however, the underlying CRT method used in CE is currently not secure. Use of these functions is still recommended so that your code can benefit from the secure versions of the methods when those become available.

See Also

Concepts

String Manipulation (CRT)

Locale

Interpretation of Multibyte-Character Sequences

_strupr_s, _strupr_s_l, _mbsupr_s, _mbsupr_s_l, _wcsupr_s, _wcsupr_s_l