Split a string in two (or three)
June 27, 2009
@lat, @lng, @zoom = @location.split(',')
This simple line will take the string @location, split it based on the comma into three strings. If location is “a,b”, then @zoom will be empty.
You will need to validate your user’s input of course, but it’s one of the ways how Ruby makes some basic tasks easy.
Entry Filed under: Uncategorized. Tags: ruby rails string split, strings.
Trackback this post | Subscribe to the comments via RSS Feed