How to reverse a string in Julia
In this shot, we will learn to reverse a string in Julia.
Julia comes with a built-in function called reverse(). The reverse() function reverses a string.
Syntax
To use this function, we use the following syntax:
reverse(string)
Parameters and returns
The reverse() function takes a string as a parameter and returns a reversed string.
Let’s use an example to understand it better.
Example
We try to reverse the Educative string in the following example.
#given stringstr = "Educative"#print the reversed stringprintln(reverse(str))
Explanation
- Line 2: We declare and initialize a string variable
strwithEducative. - Line 5: We pass the
strstring as a parameter to thereverse()function. We then print the reversed string using theprintln()function.