irb differs from script

M

Martijn Nerd

hi,

i'm trying to remove special characters from a string using iconv and it
works nicely in irb. When i run the same code in a script... it doesn't
work though :(

Any clues what could be the difference?

irb:
irb(main):001:0> require 'iconv'
=> true
irb(main):002:0> s = "genève"
=> "gen\303\250ve"
irb(main):003:0> puts s.gsub(/./) {|s| s[0].to_s + ' '}
103 101 110 195 168 118 101
=> nil
irb(main):004:0> s = "genève"
=> "gen\303\250ve"
irb(main):005:0> b = Iconv.conv('ascii//translit','UTF-8', s)
=> "geneve"
irb(main):006:0> puts b
geneve
=> nil


script:
require 'iconv'

s = "genève"
puts s.gsub(/./) {|s| s[0].to_s + ' '}
s = "genève"
b = Iconv.conv('ascii//translit','UTF-8', s)
puts b

output:
103 101 110 195 168 118 101
gen?ve


any clues anyone ?

tnx,

Martijn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top