w3resource

Ruby String Exercises: Split a delimited string and convert it to an array

Ruby String: Exercise-7 with Solution

Write a Ruby program to split a delimited string and convert it to an array.

Ruby String Exercises: Split a delimited string and convert it to an array

Ruby Code:

def check_string(my_string,d)
   return my_string.split(d)
  return my_string
end
print check_string("A,B,C,D,E,F", ",")
print "\n",check_string("A.B.C.D.E.F", ".")

Output:

["A", "B", "C", "D", "E", "F"]
["A", "B", "C", "D", "E", "F"]

Flowchart:

Flowchart: Split a delimited string and convert it to an array

Ruby Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Ruby program to remove last specified characters from a given string.
Next: Write a Ruby program to remove a substring from a specified string.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/ruby-exercises/string/ruby-string-exercise-7.php