Monday, January 23, 2006

Ruby on Rails split / explode a string

To explode or split a string using Ruby on Rails:

@m=@tag.split('-')
@my=@m[0];



Then the splitted or exploded value of the string can be accessed by using

<%= @my %>
<%= @m[0] %>
<%= @m[-1] %>

7 Comments:

At 7:06 PM, Blogger Jason said...

I don't know if this is similar to explode, but I'm trying to isolate a string from a string-double combo. Such that "25.6 feet" would become "feet"

Any ideas?

 
At 12:44 PM, Blogger Jonah Dempcy said...

Is it always going to be formatted exactly like this?

If so, just do this:

"25.6 feet".split(" ")[1]

That will just become "feet".

 
At 12:32 AM, Anonymous Anonymous said...

it really works

thanks

Kevin
winspector-fans.com

 
At 4:41 AM, Anonymous Anonymous said...

how to do thing like this
"examp\ple".split("\")[1]

 
At 10:02 PM, Blogger Unknown said...

This comment has been removed by the author.

 
At 8:35 PM, Blogger Sravan Reddy said...

I like your post very much. It is very Informative. I hope you to share more info about this.
best data science courses online

 
At 9:40 PM, Blogger Sravan Reddy said...

I like your post very much. It is very much useful for my research. I hope you to share more info about this. Keep posting Ruby On Rails Course

 

Post a Comment

<< Home

eXTReMe Tracker