unbewusst.sein
9/25/2007 10:25:00 PM
Daniel DeLorme <dan-ml@dan42.com> wrote:
>
> That doesn't work on all platforms. For me:
>
> >> require "iconv"
> => true
> >> i = Iconv.new("ASCII//TRANSLIT", "UTF-8")
> => #<Iconv:0xb7cf28e0>
> >> i.iconv("aéouï Æ")
> => "a?ou? AE"
>
> :-(
Are u sure about the encoding of "aéouï Æ" ?
because i did it with UTF-8, it works :
-- the script ----------------------------------------------------------
#! /usr/bin/env ruby
require "iconv"
i = Iconv.new("ASCII//TRANSLIT", "UTF-8")
p i.iconv("aéouï Æ")
# => "a'eou\"i AE"
p i.iconv("aéouï Æ").gsub(/[^a-zA-Z0-9 ]/, '')
# => "aeoui AE"
p i.iconv("Être ou ne pas être, c'est la question. aéouï Æ, wie heiß du
?").gsub(/[^a-zA-Z0-9' ]/, '').gsub(/[' ]/, '_').gsub(/(.*)_$/, '\1')
# => "Etre_ou_ne_pas_etre_c_est_la_question_a_eoui_AE_wie_heiss_du"
p i.iconv("Être ou ne pas être, c'est la question. aéouï Æ, wie heiß
du?").gsub(/[^a-zA-Z0-9' ]/, '').gsub(/[' ]/, '_').gsub(/(.*)_$/, '\1')
# => "Etre_ou_ne_pas_etre_c_est_la_question_a_eoui_AE_wie_heiss_du"
------------------------------------------------------------------------
--
Une Bévue