Problem with special characters like üöä (german: umlaut)

Discussion in 'Ruby' started by Dirk Einecke, Apr 12, 2004.

  1. Dirk Einecke

    Dirk Einecke Guest

    Hi.

    If I make this:
    print 'üöä'

    .... all is okay. But if I read [1] a file with the content 'üöä' and
    print the content I get this: öüä. This is very strange. Can anybody
    help me with this problem?

    [1]
    file = File.open(ENV['DOCUMENT_ROOT'] + "test5.temp", File::RDONLY)
    while line = file.gets do
    print line
    end
    file.close

    bye
    Dirk Einecke
     
    Dirk Einecke, Apr 12, 2004
    #1
    1. Advertising

  2. Dirk Einecke

    ts Guest

    >>>>> "D" == Dirk Einecke <> writes:

    D> .... all is okay. But if I read [1] a file with the content 'üöä' and
    D> print the content I get this: öüä. This is very strange. Can anybody
    D> help me with this problem?

    How have you created this file ?

    It's encoded in UTF8


    Guy Decoux
     
    ts, Apr 12, 2004
    #2
    1. Advertising

  3. Dirk Einecke

    Dirk Einecke Guest

    Hi.

    ts wrote:
    > How have you created this file ?
    >
    > It's encoded in UTF8


    The file was created with this code:

    def writeMyFile(path,content)
    file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
    content = CGI::unescapeHTML(content)
    file.write(content)
    file.close
    end

    What can I change?

    bye
    Dirk Einecke
     
    Dirk Einecke, Apr 12, 2004
    #3
  4. Dirk Einecke

    ts Guest

    >>>>> "D" == Dirk Einecke <> writes:

    D> The file was created with this code:

    Well, if you are sure that it's encoded in UTF8

    D> def writeMyFile(path,content)
    D> file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
    D> content = CGI::unescapeHTML(content)

    content = content.unpack("U*").pack("c*")

    D> file.write(content)
    D> file.close
    D> end


    Guy Decoux
     
    ts, Apr 12, 2004
    #4
  5. Re: Problem with special characters like

    ts wrote:
    >>>>>> "D" == Dirk Einecke <> writes:

    >
    >D> The file was created with this code:
    >
    > Well, if you are sure that it's encoded in UTF8
    >
    >D> def writeMyFile(path,content)
    >D> file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
    >D> content = CGI::unescapeHTML(content)
    >
    > content = content.unpack("U*").pack("c*")


    Or better: use iconv.
     
    Andreas Schwarz, Apr 12, 2004
    #5
  6. Re: Problem with special characters like üö

    Le 12 avr. 04, à 06:39, Andreas Schwarz a écrit :

    > ts wrote:
    >>>>>>> "D" == Dirk Einecke <> writes:

    >>
    >> D> The file was created with this code:
    >>
    >> Well, if you are sure that it's encoded in UTF8
    >>
    >> D> def writeMyFile(path,content)
    >> D> file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
    >> D> content = CGI::unescapeHTML(content)
    >>
    >> content = content.unpack("U*").pack("c*")

    >
    > Or better: use iconv.


    Any documentation for iconv?

    Guillaume.
     
    Guillaume Marcais, Apr 12, 2004
    #6
  7. Re: Problem with special characters like

    Guillaume Marcais wrote:
    >
    > Le 12 avr. 04, à 06:39, Andreas Schwarz a écrit :
    >
    >> ts wrote:
    >>>>>>>> "D" == Dirk Einecke <> writes:
    >>>
    >>> D> The file was created with this code:
    >>>
    >>> Well, if you are sure that it's encoded in UTF8
    >>>
    >>> D> def writeMyFile(path,content)
    >>> D> file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT)
    >>> D> content = CGI::unescapeHTML(content)
    >>>
    >>> content = content.unpack("U*").pack("c*")

    >>
    >> Or better: use iconv.

    >
    > Any documentation for iconv?


    ruby-iconv is very poorly documented
    (http://www.ruby-doc.org/stdlib/libdoc/iconv/rdoc/), but it is easy to
    use:

    converted_text = Iconv.new('iso-8859-15', 'utf-8').iconv(text)
     
    Andreas Schwarz, Apr 12, 2004
    #7
  8. Dirk Einecke

    Dirk Einecke Guest

    Hi.

    ts wrote:
    > content = content.unpack("U*").pack("c*")


    Thank you. Very much better now.

    bye
    Dirk Einecke
     
    Dirk Einecke, Apr 12, 2004
    #8
  9. Dirk Einecke

    Dirk Einecke Guest

    Re: Problem with special characters like üöä (german: umlaut)

    Hi.

    Andreas Schwarz wrote:
    > converted_text = Iconv.new('iso-8859-15', 'utf-8').iconv(text)


    That's not working in my example and I don't know how. Well - unpack and
    pack is working so I use this. Thanks for your help.

    bye
    Dirk Einecke
     
    Dirk Einecke, Apr 12, 2004
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vijay
    Replies:
    10
    Views:
    2,242
    vijay
    Apr 7, 2006
  2. =?ISO-8859-1?Q?J=FCrgen_Kahrs?=

    Umlaut characters in Unicode

    =?ISO-8859-1?Q?J=FCrgen_Kahrs?=, Nov 12, 2004, in forum: XML
    Replies:
    11
    Views:
    11,044
    =?ISO-8859-1?Q?J=FCrgen_Kahrs?=
    Nov 13, 2004
  3. Lukas Kasprowicz

    German umlaut in a string.

    Lukas Kasprowicz, Aug 12, 2003, in forum: Python
    Replies:
    5
    Views:
    678
    Christopher Boomer
    Aug 15, 2003
  4. Replies:
    8
    Views:
    792
    Jussi Salmela
    Mar 4, 2007
  5. Norbert Böschen

    textbox-umlaut-Problem, Windows 2003 server German

    Norbert Böschen, Jul 23, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    144
    Norbert Böschen
    Jul 23, 2003
Loading...

Share This Page