469,360 Members | 1,799 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,360 developers. It's quick & easy.

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

Jul 18 '05 #1
2 1499
Oliver Kurz wrote:
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.


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 && ma*@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)
Jul 18 '05 #2

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

Is this what you were looking for?

- Josiah
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Uwe Mayer | last post: by
10 posts views Thread by jojobar | last post: by
3 posts views Thread by GM | last post: by
4 posts views Thread by tinkerbarbet | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.