Question

I want to know how you split a string in ruby.

In PHP you can use the function Strstr to do this.

I have tried the following code to achieve this.

<%
video_url="http://www.youtube.com/watch?v=Zo2vav3dYnY&user=12334&name=sdetyfd"
ind=video_url.index("v=")
V=@visual.video_url[ind..15]
%>
<%=V%>

So what is the best way in ruby to do this?

Was it helpful?

Solution

It's not clear what you're after, but if you want the "v" value from the params, i would do it like so:

video_url = "http://www.youtube.com/watch?v=Zo2vav3dYnY&user=12334&name=sdetyfd"
param_hash = CGI::parse(video_url.split("?").last)
V = param_hash["v"]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top