The source code to get characters from a string using the index is given below. The given program is compiled and executed successfully.
# Ruby program to get characters from
# a string using the index.
Mystr = "Hello World";
index=0;
while index<Mystr.length
print Mystr[index]," ";
index=index + 1;
end
Output:
H e l l o W o r l d
Explanation:
In the above program, we created a string variable Mystr initialized with "Hello World". Then we traversed the string and get characters from the string one by one using index and printed them.
Program/Source Code:
The source code to get characters from a string using the index is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created a string variable Mystr initialized with "Hello World". Then we traversed the string and get characters from the string one by one using index and printed them.
need an explanation for this answer? contact us directly to get an explanation for this answer