In this shot, we’ll learn how to define a string and discuss the common methods used on a string in Rexx.
To define a string, assign a string text to a variable name.
a = "We are learning rexx - strings”say a
We are learning rexx - strings
Here some common methods used on a string in Rexx.
length(str)You can use the length method to count the number of characters in a string.
Parameters: A string or a reference variable.
Return value: An integer that represents the number of characters in the string.
reverse(str)You can use the reverse() method to return a reversed string.
Parameters: A string or a reference variable.
Return value: A string that is the reverse of the original string.
compare(str1,str2)You can use the compare() method to compare two strings.
Parameters:
str1 : A string or reference variable.str2 : Another string to compare str1 with.Return value:
0: The strings are equal.a = "Hello World"say length(a) /* 11 */say reverse(a) /* dlroW olleH */say compare(a, "Hello World") /* 0 */
The output of the code is as follows:
11
dlroW olleH
0
11 is the length of the string and dlroW olleH is the reverse of the string. 0 means that the strings are equal.