Reversing a string by characters, words or lines
The three ways to reverse text, why naive code breaks emoji, and how word and line reversal differ from a plain character flip.
Three different meanings of reverse
Reversing text is not a single operation. You can flip the individual characters, flip the order of the words, or flip the order of the lines, and each produces a very different result. A character flip of 'Ada loves code' gives 'edoc sevol adA', while a word flip gives 'code loves Ada' and a line flip only matters when there is more than one line. Choosing the right mode is the difference between scrambled letters and a cleanly re-ordered sentence.
Why naive character reversal breaks emoji
A common way to reverse a string is to split it into an array of single UTF-16 units, reverse, and join. That works for plain English but corrupts anything outside the basic range, because emoji and many symbols are stored as surrogate pairs of two units. Splitting between those units leaves broken halves that render as question marks or empty boxes. This tool avoids the trap by splitting on whole Unicode code points, so an emoji or accented letter survives the flip unchanged.
Word and line reversal keep content readable
Word mode is useful when you want to change emphasis or reorder a phrase without mangling the spelling. It reverses the sequence of words but leaves each word forwards, and it preserves the whitespace between them so the spacing pattern is not lost. Line mode operates one level up, flipping the order of whole lines while every line keeps its internal text, which is handy for turning a bottom-up log or a stacked list into the opposite order.
Palindromes and quick checks
Character reversal is the fastest way to test a palindrome by eye: reverse the word and compare it to the original. 'level' and 'racecar' come back identical, while 'hello' clearly does not. Because the reversal is instant and runs as you type, you can paste a candidate word or phrase and immediately see whether the flipped version matches, without writing any code.