Char, wchar_t, strlen, wcslen

Source: Internet
Author: User

The first part:

The wide character version of the strlen function is wcslen (wide-character string length: Wide string lengths) and is described in STRING.H (which also describes strlen) and WCHAR.H. The strlen function is described below:

size_t __cdecl strlen (const char *);        

The Wcslen function is described as follows:

size_t __cdecl wcslen (const wchar_t *);        

At this point we know that to get the length of the wide string can be called

The function returns the number of characters in a string of 6. Keep in mind that after changing to a wide byte, the character length of the string does not change, but the bit group length changes.

All of the C execution-time link library functions that you are familiar with string parameters have a wide character version. For example, wprintf is a wide-character version of printf. These functions are described in WCHAR.H and in the header file that contains the description of the standard function.

Part II:

Explanation of MSDN:
int Lstrlen (LPCTSTR lpstring);
function function: This function returns the number of bytes (ANSI version) or WCHAR value (Unicode version) of the specified string (not including the interrupt character ')
Return value: Returns the length of the specified string when the string is TCHAR. When the ANSI version is the number of bytes. Returns 0 if the string is empty.

size_t strlen (const char *string);
size_t wcslen (const wchar_t *string);
function function: Get the length of the string
Return value: Returns the number of characters in a string
Note: Returns the number of characters in a string that does not contain the string Terminator '. Wcslen is a wide-character version of strlen

Summary:
1. Lstrlen returns the number of characters in a string based on the type of the parameter (if the operating system defines Uincode, it represents a wide character, or ANSI character if undefined)
2, Wcslen returns the number of wide characters
3. Strlen returns the number of ANSI characters

Part III: Strlen and Wcslen return the number of characters, not the number of bytes that the character occupies.

Char, wchar_t, strlen, wcslen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.