Ruby array index method not working returning NIL value

Posted by Rails beginner on Stack Overflow See other posts from Stack Overflow or by Rails beginner
Published on 2012-06-09T04:13:09Z Indexed on 2012/06/09 4:40 UTC
Read the original article Hit count: 409

Filed under:

Here is the error:

=> ["Mænd med navnet Kim", "30.094", "29.946", "-148", "Kvinder med navnet Kim",
 "341", "345", "4", "Mænd med navnet Kim Hansen", "1.586", "1.573", "-13", "Kvin
der med navnet Kim Hansen", "5", "5", "0", "Mænd og kvinder med efternavnet Hans
en", "226.040", "223.478", "-2.562"]
irb(main):094:0>
irb(main):095:0* @tester.index("Mænd med navnet Kim")
=> nil
irb(main):096:0> @tester.index("Kvinder med navnet Kim")
=> 4
irb(main):097:0> @tester.index("Mænd med navnet Kim Hansen")
=> nil
irb(main):098:0> @tester.index("Kvinder med navnet Kim Hansen")
=> 12
irb(main):099:0> @tester.index("Mænd og kvinder med efternavnet Hansen")
=> nil
irb(main):100:0>

Example tried Gsub method:

<ap(&:text).map{|d| d.delete "'"}.map{|d| d.gsub("æ", "#844"}
irb(main):113:1> )
SyntaxError: (irb):112: syntax error, unexpected '}', expecting ')'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/comman
ds/console.rb:44:in `start'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/comman
ds/console.rb:8:in `start'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/comman
ds.rb:23:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'
<ap(&:text).map{|d| d.delete "'"}.map{|d| d.gsub("æ", "#844")}
Encoding::CompatibilityError: incompatible encoding regexp match (CP850 regexp w
ith UTF-8 string)
        from (irb):114:in `gsub'
        from (irb):114:in `block in irb_binding'
        from (irb):114:in `map'
        from (irb):114
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/comman
ds/console.rb:44:in `start'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/comman
ds/console.rb:8:in `start'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/comman
ds.rb:23:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

© Stack Overflow or respective owner

Related posts about ruby