How can i transform the utf8 chars to iso8859-1

前端 未结 2 819
日久生厌
日久生厌 2021-01-16 07:11

the question is that the title say! who can tell me how do this in ruby!

2条回答
  •  清酒与你
    2021-01-16 07:31

    ~ UPDATE ~

    ruby-iconv has been superseded from Ruby 1.9.3 onwards by the encode method. See Jörg W Mittag's answer for details, but in short:

    utf8string = "èàòppè"
    iso_string = utf8string.encode('ISO-8859-1')
    

    I agree with Williham Totlandt in thinking that this type of conversion might not be the smartest idea ever, but anyway: use ruby-iconv :)

    utf8string = "èàòppè"
    iso_string = Iconv.conv 'iso8859-1', 'UTF-8', utf8string 
    

提交回复
热议问题