Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Christian Meichtry http://dr.corbeille.info

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Convert a UTF-8 string to ISO-8859-1

Convert a utf string to iso, used this when generating a pdf with pdf-writer in Rails, all my text is UTF8 but pdf-writer does not support this.

   1  
   2  #add this to environment.rb
   3  #call to_iso on any UTF8 string to get a ISO string back
   4  #example : "Cédez le passage aux français".to_iso
   5  
   6  class String
   7    require 'iconv' #this line is not needed in rails !
   8    def to_iso
   9      Iconv.conv('ISO-8859-1', 'utf-8', self)
  10    end
  11  end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS