Описание тега string-comparison
String comparison is the action of comparing strings.
The result of a string comparison may be a boolean or an integer; if it is an integer, then this measures the distance between the two strings, usually lexicographic distance. Note that this means that the strings are equal when the comparison yields 0.
There are some issues to be considered when comparing strings. First, there is the underlying type and encoding of the strings (Unicode? 8-byte chars? 16-byte chars?). Second, there is the question if case is relevant.
A classical mistake for beginning programmers is to compare strings using ==
, or whatever other operator their programming language uses for comparing primitive types. In some languages, like Java and C, this will compare the instance of the strings (their reference or memory address, respectively), instead of the string itself.
Most programming languages provide built-in functions for comparing strings.