Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

reverse

Reverse order of characters in string

Syntax

newStr = reverse(str)

Description

example

newStr = reverse(str) reverses the order of the characters of each element of str.

Examples

collapse all

Reverse the strings in a string array and find strings that read the same when reversed. Starting in R2017a, you can create strings using double quotes instead of the string function.

str = ["airport","control tower","radar","runway"]
str = 1x4 string array
    "airport"    "control tower"    "radar"    "runway"

newStr = reverse(str)
newStr = 1x4 string array
    "tropria"    "rewot lortnoc"    "radar"    "yawnur"

tf = (newStr == str)
tf = 1x4 logical array
   0   0   1   0

str(tf)
ans = 
"radar"

Input Arguments

collapse all

Input text, specified as a string array, character vector, or cell array of character vectors.

Output Arguments

collapse all

Output text, returned as a string array, a character vector, or a cell array of character vectors. str and newStr are the same data type.

Data Types: string | char | cell

Extended Capabilities

See Also

| | | | | |

Introduced in R2016b

Was this topic helpful?