Created
July 14, 2010 00:23
-
-
Save chrisdarroch/474802 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string = "this is a string" | |
string.split("is") #=> ["th", " ", " a string"] | |
string.split("is a") #=> ["this ", " string"] | |
first, last = string.split("is a") | |
puts first #=> "this " | |
puts last #=> " string" | |
first, last = string.split("a string") | |
#=> ["this is "] | |
puts first #=> "this is " | |
puts last #=> nil | |
first, last = string.split("this is") | |
#=> ["", " a string"] | |
puts first #=> "" | |
puts last #=> " a string" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment