Skip to content

Latest commit

 

History

History
12 lines (11 loc) · 450 Bytes

split_strings.md

File metadata and controls

12 lines (11 loc) · 450 Bytes

Splitting a String in Ruby

Here are a few different ways in which you can split strings in Ruby.

#!/usr/bin/ruby
str = "Hello World! This is how you split strings"
puts str
puts str.split(/ /) 	# Splits by strings separated by spaces
puts str.split(//) 		# Split by individual letter
puts str.split(//, 3) 	# The second parameter determines how many splits are performed
puts str.split("o") 	# Splits at a letter or string of letters