Best way to convert string a to utf-*

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Oliver Kurz

    Best way to convert string a to utf-*

    Hello,

    could someone tell me the best way to convert a string to utf, for example
    to utf-8?

    The problem: I have no controll about the source where the string comes
    from. It could have any possible characterset. And I have to convert it for
    example to utf-8.

    Is there a good way to do this? And when, how?

    Is there a function which tell me, what is the characterset of the string at
    the moment?

    Would be create, when someone could help me!

    cu
    Oliver



  • Erik Max Francis

    #2
    Re: Best way to convert string a to utf-*

    Oliver Kurz wrote:
    [color=blue]
    > could someone tell me the best way to convert a string to utf, for
    > example
    > to utf-8?
    >
    > The problem: I have no controll about the source where the string
    > comes
    > from. It could have any possible characterset. And I have to convert
    > it for
    > example to utf-8.[/color]

    If the format is not already a Unicode string, you really can't know
    what encoding it's in. To convert it to UTF-8 (or UTF-16 or UTF-32),
    you really must know what format it's in to begin with or otherwise
    you're stuck.

    --
    __ Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
    / \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
    \__/ He who conceals his disease cannot expect to be cured.
    -- (an Ethiopian proverb)

    Comment

    • Josiah Carlson

      #3
      Re: Best way to convert string a to utf-*


      s = u"some unicode string"
      utf_8_encoded = s.encode('utf-8')

      Is this what you were looking for?

      - Josiah

      Comment

      Working...