Splitting and Joining
split, join, chars.
Splitting a String
The split method breaks a string into an array using a separator. By default it splits on whitespace.
sentence = "the quick brown fox"
words = sentence.split
puts words.inspectSplitting on a Delimiter
Pass any string as the separator, such as a comma for CSV-style data.
csv = "red,green,blue"
puts csv.split(",").inspectAll lessons in this course
- String Basics and Methods
- Interpolation and Formatting
- Searching and Replacing
- Splitting and Joining