Strcmp wcscmp stricmp wcsicmp ()

Source: Internet
Author: User

C ++For numeric data, you can use "=" to compare whether the values are equal, but it is not applicable to string comparison. We can use the following two functionsCompare whether two strings are equal.

1,Strcmp

This isUsed For ANSI standard stringsFunction (such as string and char *), which accepts two string buffers as parameters,Returns zero if the two strings are the same.. Otherwise, if the value of the first input string is greater than the return value of the second string, it is greater than zero. If the value of the first input string is smaller than the return value of the second string, it is less than zero.

Char * Ch = "Xiangxiang sugar ";
If (Strcmp(CH, "Xiangxiang sugar") = 0)
{
//Equal strings
}
Else
{
//Strings are not equal
}

 

2,Wcscmp

This function is a unicode Series function corresponding to strcmp. It is used in the same way as strcmp.Compare whether two Unicode strings are equal(Such as wstring and wchar_t *).

Wchar_t * Ch = l "Xiangxiang sugar ";
If (Wcscmp(CH, l "Xiangxiang sugar") = 0)
{
//Equal strings
}
Else
{
//Strings are not equal
}

 

Note: The comparison functions described above are case-sensitive for English. Even if the letters are the same but the cases are different, the functions will regard the two strings as different.

We have discussed how to compare the two strings to determine whether they are equal, Which is case sensitive. Today, we also introduce two functions that determine whether a string is equal. The difference is thatThey are case insensitive.That is, the function does not distinguish whether the strings are in the same case, as long as each letter is the same.

1,Stricmp

This isUsed For ANSI standard stringsFunction (such as string and char *), which accepts two string buffers as parameters,If the two strings are the same, zero is returned, Which is case insensitive.. Otherwise, if the value of the first input string is greater than the return value of the second string, it is greater than zero. If the value of the first input string is smaller than the return value of the second string, it is less than zero.

Char * Ch = "ABCD ";
If (Stricmp(CH, "ABCD") = 0)
{
//Equal strings
}
Else
{
//Strings are not equal
}

 

2,Wcsicmp

This function is a unicode Series function corresponding to stricmp. It is used in the same way as stricmp.Checks whether two Unicode strings are equal and case insensitive.(Such as wstring and wchar_t *).

Wchar_t * Ch = l "ABCD ";
If (Wcsicmp(CH, l "ABCD") = 0)
{
//Equal strings
}
Else
{
//Strings are not equal
}

Strcmp wcscmp stricmp wcsicmp ()

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.