| The Renegade Coder (original) (raw)
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: print(sys.argv[1][::-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:
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:
- Reverse a String in Java
- Reverse a String in Python
- Reverse a String in Ruby
- Reverse a String in Scheme
- 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!
Sample Programs in Every Language (44 Articles)—Series Navigation
For 100 Days of Code, I’ve decided to implement a few sample programs in as many languages as possible. Each implementation details a brief history of the language and a description of the code.
The plan for the series is to explore the major general-purpose language like Java, Python, C, C++, and C#. From there, we’ll take a look at some sample programs in web development languages like Ruby, PHP, and JavaScript. As we continue, we’ll cover proprietary languages like Swift and Objective-C. Eventually, we’ll start to tackle less popular languages like Rust, x86, and Verilog. Finally, we’ll play around with some of the esoteric languages like Brainf*ck and LOLCODE.
Who knows? Maybe the Sample Programs in Every Language series will become so popular it’ll never end. To help this series grow, consider sharing it on social media with your friends. Or, if you have a language you want to see, drop your suggestion in the comments.
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. Then, he earned a master's in Computer Science and Engineering. Most recently, he earned a PhD in Engineering Education and now works as a Lecturer. In his spare time, Jeremy enjoys spending time with his wife and kid, playing Overwatch 2, Lethal Company, and Baldur's Gate 3, reading manga, watching Penguins hockey, and traveling the world.
Recent Posts
link to The Problem With Centrism: A Case Study
The Problem With Centrism: A Case Study
While Channel 5 always felt like a goofy street interview channel, it has since taken more of an independent media approach, one which holds an enlightened centrist position.
link to Reflecting on My First Two Years as a Lecturer
Reflecting on My First Two Years as a Lecturer
I just wrapped up the end of an another academic year, and I wanted to take a moment to reflect on it. While I still love my job, I think this has been one of my rougher years for teaching.