0

I want to get two separate value from

/en/faq

the two separate value will be

lang =en
rem  =faq

I have used to split which was relatively much easier. Nonetheless, this is my approach which needs tweaking around, hopefully from your help I will be able to accomplish it.

string = "/en/faq"
lang   = string.split("/").first
rem    = string.split("/en/")

puts "/#{lang}/#{rem[1]}"

The desired output should be "/en/faq/" but the output is

"//faq" 

i know i have got '.first' which is why I am getting a null value but could anyone help on getting the right results please?

thanks in advance.

3
  • 1
    try lang = string.split("/") and puts "/#{lang[1]}/#{rem[1]}" Commented Nov 13, 2012 at 11:31
  • oh my god you are genius dude thats exactly what i have done just now, thanks :) Commented Nov 13, 2012 at 11:33
  • to implement that in application.html.erb. would i just put them inside <% ................. %> ?? thanks in advance Commented Nov 13, 2012 at 11:38

1 Answer 1

1
string = "/en/faq"
lang   = string.split("/")
rem    = string.split("/#{lang[1]}/")

puts "/#{lang[1]}/#{rem[1]}"

this does the trick and thanks to Sebi for his prompt answer!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.