Reverse a String in Every Language

Reverse a String in Every Language Featured Image

Welcome to Reverse a String in Every Language: a series of articles demonstrating string reversal in as many languages as possible.

Table of Contents

What is Reverse a String?

In code, string reversal is the process of flipping the characters in a string such that the resulting string contains all the original characters but in reverse order. For example, let’s say we have some string:

"Hello, World!"

If we reverse this string, we end up with the following string:

"!dlroW ,olleH"

As we can see, we’ve generated a new string with each character in the reverse order.

Often times, the solution for this kind of problem is to grab the character array and produce a new string by reading the original string in reverse. In some cases, it’s even possible to reverse that array in place.

I’m sure you’ll find many different implementations throughout this collection. Personally, I’m fond of python which uses a slice:

import sys

if len(sys.argv) > 1:

If you’re interested in trying this in your favorite language, why not check out the documentation for our specific set of rules? Once you’re ready, fork the repo and make a pull request with your changes.

Why Reverse a String in Every Language?

When I started building up the sample programs repository, I only had one code snippet for each language: Hello World. While Hello World is a fun program, it doesn’t do a great job of showing off language features. As a result, I decided to expand the repository to support other kinds of programs.

Of course, there are a couple archives that already exist for more advanced snippets:

  1. 99 Bottles of Beer
  2. FizzBuzz

In fact, I’m probably wasting my time as Rosetta Code already hosts the largest database of coding snippets I’ve ever seen. That said, I’m not here to compete, I’m here to learn.

Regardless, where else are you going to find a place to read my ramblings about every language?

An Alphabetical List of Languages

As with the Hello World series, I don’t release articles in any sort of order. To help provide some sort of easy to use archive, I’ve decided to list all of the Reverse a String implementations here in alphabetical order:

  1. Reverse a String in Java
  2. Reverse a String in Python
  3. Reverse a String in Ruby
  4. Reverse a String in Scheme
  5. Reverse a String in Swift

Once again, thank you for your support. If there’s a language you’d like to see in this series, drop it down below in the comments. Also, don’t forget to share this article with your friends. It helps the series grow!

Series Navigation← Hello World in GobyReverse a String in Python →

Jeremy Grifski

Jeremy grew up in a small town where he enjoyed playing soccer and video games, practicing taekwondo, and trading Pokémon cards. Once out of the nest, he pursued a Bachelors in Computer Engineering with a minor in Game Design. After college, he spent about two years writing software for a major engineering company. Today, he pursues a PhD in Engineering Education in order to ultimately land a teaching gig. In his spare time, Jeremy enjoys spending time with his wife, playing Overwatch and Phantasy Star Online 2, practicing trombone, watching Penguins hockey, and traveling the world.

Recent Content