473,320 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

string conversion latin2 to ascii

Hi all,

sorry for a newbie question. I have unicode string (or better say
latin2 encoding) containing non-ascii characters, e.g.

s = "Ukázka_možnosti_využití_programu_OpenJUMP_v_S OA"

I would like to convert this string to plain ascii (using some lookup
table for latin2)

to get

-Ukazka_moznosti_vyuziti_programu_OpenJUMP_v_SOA

Thanks for any hits! Regards, Martin Landa
Nov 27 '07 #1
5 2609
On Nov 27, 3:35 pm, Martin Landa <landa.mar...@gmail.comwrote:
Hi all,

sorry for a newbie question. I have unicode string (or better say
latin2 encoding) containing non-ascii characters, e.g.

s = "Ukázka_možnosti_využití_programu_OpenJUMP_v_S OA"

I would like to convert this string to plain ascii (using some lookup
table for latin2)

to get

-Ukazka_moznosti_vyuziti_programu_OpenJUMP_v_SOA

Thanks for any hits! Regards, Martin Landa
With a little googling, I found this:

http://www.peterbe.com/plog/unicode-to-ascii

You might also find this article useful:

http://www.reportlab.com/i18n/python..._tutorial.html

Mike
Nov 27 '07 #2
sorry for a newbie question. I have unicode string (or better say
latin2 encoding) containing non-ascii characters, e.g.

s = "Ukázka_moĹľnosti_vyuĹľitĂ*_programu_OpenJUMP_v_S OA"
That's not a Unicode string (at least in Python 2); it is
a latin-2 encoded byte string; it has nothing to do with Unicode.
I would like to convert this string to plain ascii (using some lookup
table for latin2)

to get

-Ukazka_moznosti_vyuziti_programu_OpenJUMP_v_SOA
I recommend to use string.translate. You need a translation
table there, which is best generated with string.maketrans.

table=string.maketrans("ážĂ*","azi")
print s.translate(table)

HTH,
Martin
Nov 27 '07 #3
On Nov 28, 8:45 am, kyoso...@gmail.com wrote:
On Nov 27, 3:35 pm, Martin Landa <landa.mar...@gmail.comwrote:
Hi all,
sorry for a newbie question. I have unicode string (or better say
latin2 encoding) containing non-ascii characters, e.g.
s = "Ukázka_možnosti_využití_programu_OpenJUMP_v_S OA"
I would like to convert this string to plain ascii (using some lookup
table for latin2)
to get
-Ukazka_moznosti_vyuziti_programu_OpenJUMP_v_SOA
Thanks for any hits! Regards, Martin Landa

With a little googling, I found this:

http://www.peterbe.com/plog/unicode-to-ascii
and if the OP has the patience to read *ALL* the comments on that blog
entry, he will find that comment[-2] points to

http://effbot.python-hosting.com/fil...xt/unaccent.py

and comment[-1] (from the blog owner) is "Brilliant! Thank you."

The bottom line is that there is no universal easy solution; you need
to handcraft a translation table suited to your particular purpose
(e.g. do you want u-with-umlaut to become u or ue?). The
unicodedata.normalize function is useful for off-line preparation of a
set of candidate mappings for that table; it should not be applied
either on-line or blindly.

Cheers,
John
Nov 27 '07 #4
* Martin Landa <la**********@gmail.com>, 2007-11-27:
I have unicode string (or better say latin2 encoding) containing
non-ascii characters, e.g.

s = "Ukázka_možnosti_využití_programu_OpenJUMP_v_S OA"

I would like to convert this string to plain ascii (using some lookup
table for latin2)

to get

-Ukazka_moznosti_vyuziti_programu_OpenJUMP_v_SOA
You may try python-elinks
<http://freshmeat.net/projects/python-elinks/>:

>>import elinks
print "Ukázka_mo\236nosti_vyu\236ití_programu_OpenJUMP_v _SOA".decode('Windows-1250').encode('ASCII', 'elinks')
Ukazka_moznosti_vyuziti_programu_OpenJUMP_v_SOA
--
Jakub Wilk
Nov 28 '07 #5
On Nov 27, 5:08 pm, John Machin <sjmac...@lexicon.netwrote:
On Nov 28, 8:45 am, kyoso...@gmail.com wrote:


On Nov 27, 3:35 pm, Martin Landa <landa.mar...@gmail.comwrote:
Hi all,
sorry for a newbie question. I have unicode string (or better say
latin2 encoding) containing non-ascii characters, e.g.
s = "Ukázka_možnosti_využití_programu_OpenJUMP_v_S OA"
I would like to convert this string to plain ascii (using some lookup
table for latin2)
to get
-Ukazka_moznosti_vyuziti_programu_OpenJUMP_v_SOA
Thanks for any hits! Regards, Martin Landa
With a little googling, I found this:
http://www.peterbe.com/plog/unicode-to-ascii

and if the OP has the patience to read *ALL* the comments on that blog
entry, he will find that comment[-2] points to

http://effbot.python-hosting.com/fil...xt/unaccent.py

and comment[-1] (from the blog owner) is "Brilliant! Thank you."

The bottom line is that there is no universal easy solution; you need
to handcraft a translation table suited to your particular purpose
(e.g. do you want u-with-umlaut to become u or ue?). The
unicodedata.normalize function is useful for off-line preparation of a
set of candidate mappings for that table; it should not be applied
either on-line or blindly.

Cheers,
John
Sorry...I didn't know about translation tables or I would have
mentioned that instead. My bad.

Mike
Nov 28 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: john | last post by:
On my form i have a message box called txtItemDesc that displays the french phrase qualité Père Noël. Now then when i run this code on that text box: Dim chrArr() As Char chrArr =...
6
by: Willem | last post by:
What is the best way to calculate an ascii string into an integer (not talking about an atoi conversion): For examle if I have the ascii string: "/b" then in hex it would be 2F7A and if I...
4
by: Dennis Myrén | last post by:
Hi. Is there a way to utilize the great primitive data type formatting routines available in .NET without working with strings? I want a byte directly rather than a string. I think it is...
3
by: pkumar | last post by:
How to convert this byte array to string byte b=new byte; Is there any function or I need read one by one and build the string thanks
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
30
by: Steve Edwards | last post by:
Hi, I'm re-writing some code that had relied on some platform/third-party dependent utility functions, as I want to make it more portable. Is there a standard C/C++/stl routine for changing an stl...
0
by: Grzesiek | last post by:
Hey there! Please help me... I've got a iSeries (AS 400 with DB2), and I must connect to this database from Linux. On AS400 I've this settings (which I can't change): Language: Polish...
5
by: Jamie Risk | last post by:
This is the code snippet that I've come up to convert a byte to string. Is there a best practiced method for such a conversion? - Jamie public static string ByteArrayToString(byte array) {...
4
by: vcnewbie | last post by:
Hi I'm maintaining a VisualC++ project to increase its security regarding stored passwords. I thought about using SHA256Managed to create a hash for the password when creating a user and when...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.