compareText(): order textual values
compareText(x, y) compares text and returns a negative, zero, or positive result according to their ordering. It is useful when strings must be sorted or a program needs to decide which label comes first.
Text order versus numeric order
Text comparison follows character and collation rules, so “10” may come before “2” in ordinary lexical order. When labels contain meaningful embedded numbers, choose compareNatural() instead. For a general comparator that works beyond strings, use compare().
Useful companions
Use sort() to arrange a list, equalText to test textual equality, and concat() to prepare labels before comparing. format() can normalize numbers for display.
Be explicit about normalization
Case, accents, whitespace, and locale may affect results. Normalize data according to the user-facing rule before comparison, and avoid using text ordering as evidence that two numerical quantities are equal.