There are several ways of comparison, but I always see that the most indicated are ( ===, strcmp ou strcasecmp
).
Among these forms considered the safest (according to some websites), the following doubts follow:
There are several ways of comparison, but I always see that the most indicated are ( ===, strcmp ou strcasecmp
).
Among these forms considered the safest (according to some websites), the following doubts follow:
You are referring to different approaches. Although both compare two strings which return (or say about strings) is different.
===
returns only a Boolean, true, or false.
strcmp
returns negative ( <0
) if the first string passed to the function is less than the second; positive otherwise; and zero if they are equal.
It can be said that ===
is to know if they are identical, and strcmp
is to compare strings returning 3 possibilities.
strcasecmp
is a variant of strcmp
but case-insensitive , ignoring whether it has large or small letters.
It is only possible to compare performance differences in the case of both in commun, that is, if you want to compare if two strings are identical.
So, given that strcmp
and strcasecmp
need another check to know the result it becomes obvious that ===
is faster. Either strcmp runs first strcmp(strA, strB)
and then have to have another equality check == 0
. I have found some numbers here that point to faster 3x performance using ===
.
If you want to know if two strings are identical, you must use ===
.
Use === if you want to know if they are identical.
If you want to know which is the largest of which user strcmp.
Do not be alone in this post go as far as you can in knowledge.