Lua .reverse()

Brag2gr8's avatar
Published Sep 8, 2023
Contribute to Docs

The .reverse() function takes a valid string and rearranges it in reverse order.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.
    • Beginner Friendly.
      4 hours

Syntax

string.reverse(originalString)

The originalString is the string to be reversed.

Example

The code below demonstrates a basic implementation of the .reverse() method:

originalString = "Hello, World!"
newString = string.reverse(originalString)
print(newString)

This will return the following output:

!dlroW ,olleH

All contributors

Contribute to Docs

Learn Lua on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.
    • Beginner Friendly.
      4 hours