strcmp () comparison functions and strcasecmp () and strnatcmp ()

Source: Internet
Author: User

The function prototype for strcmp () is as follows ()

int strcmp (string str1,string str2)

The function requires two parameter strings for comparison, and if the two strings are equal, the function returns 0, if the dictionary order str1 after str2 (greater than STR2) returns a positive number, otherwise, returns a negative number, which is case-sensitive.
The function strcasecmp () is the same as strcmp () except for case insensitive.
function strnatcmp () is case-sensitive and differs from strcmp ()
The strnatcmp () function uses a "natural" algorithm to compare two of strings. In natural algorithms, the number "2" is less than the number "10". In the computer sort, "2" is greater than "10", because "2" is greater than the first number of "10".

The function returns:

0-If two strings are equal
<0-if string1 is less than string2
>0-if string1 is greater than string2

Example:

<?phpecho strnatcmp ("2Hello world!", "10Hello world!"); echo "<br/>"; Echo strnatcmp ("10Hello world!", "2Hello world!"); >

Output:

-11

strcmp () comparison functions and strcasecmp () and strnatcmp ()

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.