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: , .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Recent posts

Starting to learn Rails?

Archive

Recent comments

allaboutruby on Post ruby or html, css, sql so…
Wolf on Post ruby or html, css, sql so…
allaboutruby on Google Maps API in Rails (YM4R…
Christian on Google Maps API in Rails (YM4R…
Pankaj Sisodiya on Installing Rails on Windows (3…