reverse

Reverses the order of the characters in text.

Category: Language Fundamentals > Data Types

Syntax

newStr = reverse(str)

Returns str with its characters in reverse order.

Description

For a string array, every string is reversed on its own and the order of the strings stays the same. To reverse the order of the elements of a numeric array or cell array use flip instead; reverse accepts text only.

Input arguments

str
String array or character vector.

Output arguments

newStr
Same type and size as str; each element is reversed individually.

Example

reverse('hello')
reverse(["ab", "cd"])
Output
ans = 'olleh'
ans = 1×2 string array

    "ba"    "dc"

See also

flip fliplr strrep upper lower