Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

lua
communitycreator

How to reverse a string in Lua

Dario Vincenzo Tarantini

In Lua, there are many functions that are useful to manipulate strings. We can use the string.reverse function if we need to reverse a string.

%0 node_1 Hello, Educative! node_3 string.reverse() node_1->node_3 node_1635717539976 !evitacudE ,olleH node_3->node_1635717539976
A visual representation of string.reverse()

Syntax

string = string.reverse(string)

Parameters

The function only needs a valid string as a mandatory parameter.

Return value

The reverse function will reverse the string given as input.

Code

In this example, we will reverse the string "Hello, Educative!":

ourstring = "Hello, Educative!"
print(string.reverse(ourstring))

Expected output

!evitacudE ,olleH

RELATED TAGS

lua
communitycreator

CONTRIBUTOR

Dario Vincenzo Tarantini
RELATED COURSES

View all Courses

Keep Exploring