CCalclabhub

How To Reverse Text Calculator

Reversing text is the simplest string operation there is, and also one of the easiest to get subtly wrong once the text leaves plain English and starts containing emoji or accented letters.

Reversed

txet fo enil siht esreveR

Characters in
25
Lines in
1
Characters out
25

Character mode reverses the whole string, word mode keeps the words intact and flips their order, and line mode reverses the lines.

The formula this calculator uses

reverse(s) = the characters of s in the opposite order

s
The input string
reverse(s)
The same characters in the opposite order
n
The number of characters in the string

How to check the result by hand

  1. 1

    Decide what to reverse

    Characters flip the whole string, words flip the order of the words, and lines flip the order of the lines. They are three different operations.

  2. 2

    Split the text into the right units

    For characters, take the string apart one code point at a time. For words or lines, split on spaces or newlines first.

  3. 3

    Reverse the order of the units

    Walk the list from the end to the beginning and write the units out in that order.

  4. 4

    Reassemble the text

    Join the reversed units back together with the same separators they had before, so word spacing and line breaks are preserved.

  5. 5

    Check for broken characters

    If the text contained emoji or accented letters, confirm they still render. Reversing code units rather than code points is what breaks them.

For worked examples, common mistakes and the limits of this formula, read the full How To Reverse Text page.