# compareText() Function & Examples

Use the compareText() relational function in Calcul.io. Review its syntax, edit working examples, understand the result, and explore related math functions.

## compareText

#### compareText(x, y)

Try it yourself:

```calculio
compareText("B", "A")
compareText("A", "B")
compareText("A", "A")
compareText("2", "10")
compare("2", "10")
compare(2, 10)
compareNatural("2", "10")
compareText("B", ["A", "B", "C"])
```

[compare](https://calcul.io/function/compare/index.md)

---

## 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()](https://calcul.io/function/compareNatural/index.md) instead. For a general comparator that works beyond strings, use [compare()](https://calcul.io/function/compare/index.md).

## Useful companions

Use [sort()](https://calcul.io/function/sort/index.md) to arrange a list, [equalText](https://calcul.io/function/equalText/index.md) to test textual equality, and [concat()](https://calcul.io/function/concat/index.md) to prepare labels before comparing. [format()](https://calcul.io/function/format/index.md) 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.

[All functions](https://calcul.io/functions/index.md)
