Reverse a string
A practical review of string reversal: what it changes in stored text, when it is suitable, and how copy, search, and accessibility are affected.
Is this transformation suitable for your intended use?
Reversing a string is suitable when you need the stored character sequence itself turned around: palindrome checks, programming exercises, puzzle or cipher play, and processing pipelines that treat text as an ordered sequence of units. The main benefit is a deterministic, lossless reorder of those units. Every original unit remains present; only their order changes.
The decisive tradeoff is that natural reading order is destroyed. For ordinary language, the result is usually still valid text and still copyable, yet it is no longer readable as the original sentence. Search, spell-check, translation, and most editing tools will treat the reversed sequence as a different string. Use reversal when order is the point of the task. Prefer the original plain text whenever meaning, findability, or downstream editing still matter.
- Choose reversal for puzzles, palindromes, teaching order-sensitive algorithms, or novelty display where unreadability is acceptable.
- Keep the original plain text for names, messages, documents, identifiers, and anything that must remain searchable, quoted, or edited later.
- Keep a reversible copy of the source if you may need to restore reading order. Character-order reversal is invertible when the same unit definition is used both ways.
What reversing a string actually changes
In its strict sense, reversing a string changes stored order. The transformation walks the text from the last unit to the first and writes that new sequence. It does not restyle glyphs, substitute lookalike letters, or leave the original characters in place while flipping how they are drawn. No sample input and output were supplied with this brief, so the mechanism below is the general definition of reversal rather than a check against a particular tool’s example.
The word reverse is often used loosely. Mirror usually means a left-to-right visual flip of glyph shapes, as if the line were seen in a looking glass. Font usually means a typeface, not a reorder. Unicode substitution replaces letters with different code points that happen to look flipped or stylized. CSS or other presentation layers can scale or transform the rendered line while leaving the stored string unchanged. Bidirectional display can show right-to-left scripts in visual order without reversing the stored characters. Those are different operations. Only stored reversal, and Unicode substitution, change the characters that get copied.
| Label people use | What actually changes | Stored text after copy |
| Character or code-point reverse | Order of Unicode code points | Reversed code-point sequence |
| Grapheme reverse | Order of user-perceived characters | Reversed grapheme clusters, marks usually kept with their bases |
| Word reverse | Order of words; letters inside each word stay put | New word order, original spelling inside words |
| Mirrored appearance | How glyphs are drawn, or substituted lookalikes | Unchanged if presentation-only; different code points if substitution |
| Bidirectional display | Visual layout of mixed-direction text | Original stored order unless a reverse was also applied |
The unit you reverse decides whether the result is merely reordered or actually broken. Reversing by Unicode code point is common in programming libraries. Combining marks then move independently of their base letters, so a letter-plus-accent sequence can become an accent followed by a letter and may render as two pieces instead of one accented character. Multi-code-point emoji (zero-width joiner sequences, skin-tone modifiers, flag pairs) can split into parts that no longer form the original picture. Reversing by grapheme cluster keeps those groups together and is the safer definition when the input may contain marks or emoji. Word-level reversal is a different transformation: it changes sentence order, not letter order.
Code-point reverse (ASCII): hello -> olleh
Word reverse: hello world -> world hello
Grapheme-aware reverse keeps a base letter with its combining mark as one unit.
Code-point reverse of the same pair can detach the mark from the letter.
Presentation-only mirroring, including a horizontal flip in a stylesheet or graphics tool, does not reverse the string. The file or clipboard still holds the original order. That distinction matters when someone asks for a reverse and is shown a mirrored look: the screen may appear flipped while search, paste, and export still carry the source text.
Will the result stay readable and usable after copying or sharing?
If the transformation rewrites stored order, copy and paste carry the reversed sequence into other apps. Recipients, search boxes, and editors see the new order, not the original sentence. There is no hidden original behind the glyphs. A plain-text equivalent of the source is needed whenever anyone must still read, quote, index, or edit the meaning.
Reading order follows the stored sequence in typical plain-text contexts. Assistive technology that speaks or brailles the characters in document order will therefore present the reversed string as reversed speech or braille. That is the expected consequence of changing stored order; it is not a verified test of a named screen reader, browser, or operating system in this review, and one successful rendering in a single app would not guarantee the same behavior everywhere.
- Search and find: queries written in normal spelling will not match a character-reversed body, and vice versa.
- Editing: caret movement, spell-check, autocomplete, and length limits all operate on the reversed sequence.
- Identifiers and data: reversed tokens generally fail equality checks against the original (passwords, names, codes, URLs as text).
- Presentation-only flips: copy usually yields the original string, so sharing can silently drop the visual effect.
- Unicode substitution used as a fake reverse: copy yields different characters that may fail fonts, sorting, and search against the original letters.
Compatibility limits follow from the unit choice. Broken combining sequences and split emoji are still Unicode, but they may render as boxes, extra marks, or several symbols depending on the destination font and renderer. Environments that normalize text on paste may recompose or reorder marks, so a round trip can differ from the reversed buffer you copied. Mixed left-to-right and right-to-left characters add another layer: reversing stored order is not the same as applying the Unicode bidirectional algorithm, and the visual line after paste can surprise you even when the code points are exactly reversed.
Keep the original plain text beside any reversed copy if the work must remain accessible, searchable, or recoverable. Use grapheme-aware reversal when the input is real writing rather than a pure ASCII token. Treat mirrored looks and fancy substituted characters as display effects, not as a string reverse, unless you have confirmed that the stored code points themselves were reordered.