Reverse Text Tool: Character Reversal, Word Order Inversion & Line Flipping
Reverse characters, flip entire word sequences, or invert multi-line document ordering with customizable whitespace and linebreak preservation.
String Reversal Algorithms & Unicode Surrogate Pairs
A simple naive split (str.split("").reverse().join("")) works for basic ASCII, but breaks multi-byte Unicode surrogate pairs (such as emojis or accented characters):
- Surrogate Pair Inversion: A 4-byte emoji (like 😃) consists of high and low 16-bit surrogate code units. Splitting raw strings reverses the pair, corrupting the emoji into broken fallback symbols.
- Array.from() Iteration: Our algorithm uses Unicode-aware iterator slicing (
Array.from(str).reverse().join("")), safely preserving emojis and compound glyphs.
Three Distinct Reversal Modes
Tailor your text reversal operation to your data structure:
- Reverse Entire Text: Inverts every character from end to beginning.
- Reverse Words Only: Reverses word order while keeping individual words legible (e.g., "The quick brown fox" → "fox brown quick The").
- Flip Line Order: Inverts the vertical order of lines in a list, placing the last line at the very top.
Pro Tip: Practical Application
Use "Flip Line Order" to instantly invert chronological server access logs so the most recent log entries appear at the top of your screen.