compareText

compareText(x, y)

Try it yourself:

See also:

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.

Try Compare Text in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions