[Ror-es] Buscar dentro de un string (split)

Ale Muñoz bomberstudios at gmail.com
Sun Sep 23 12:31:48 GMT 2007


On 9/23/07, Zaid Dd <ruby-forum-incoming at andreas-s.net> wrote:
> Hoooola
>
> Tengo en los parámetros recividos por el navegador esto:
> itemlist=Sobre+el+Bar1Juegos1D%C3%B3nde+Estamos1Contactar1
>
> Sabeis como puedo buscar la posición en la q está el "1" y meterlo en
> variables


Así de repente puedes hacer

require 'strscan'

foo = "Uno1Dos1Tres1Cuatro"
s = StringScanner.new(foo)
number_of_chars = foo.scan(/1/).size
position_of_chars = []
number_of_chars.times do
  s.scan_until(/1/)
  position_of_chars << s.pos
end

puts position_of_chars

Pero me extrañaría muchísimo que no hubiera una función que haga lo mismo :)


-- 
Ale Muñoz
http://sofanaranja.com
http://bomberstudios.com


More information about the Ror-es mailing list