473,804 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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žnost i_využití_progr amu_OpenJUMP_v_ SOA"

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

to get

-Ukazka_moznosti _vyuziti_progra mu_OpenJUMP_v_S OA

Thanks for any hits! Regards, Martin Landa
Nov 27 '07 #1
5 2630
On Nov 27, 3:35 pm, Martin Landa <landa.mar...@g mail.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žnost i_využití_progr amu_OpenJUMP_v_ SOA"

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

to get

-Ukazka_moznosti _vyuziti_progra mu_OpenJUMP_v_S OA

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Ĺľno sti_vyuĹľitĂ*_p rogramu_OpenJUM P_v_SOA"
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_progra mu_OpenJUMP_v_S OA
I recommend to use string.translat e. You need a translation
table there, which is best generated with string.maketran s.

table=string.ma ketrans("ážĂ* ","azi")
print s.translate(tab le)

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...@g mail.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žnost i_využití_progr amu_OpenJUMP_v_ SOA"
I would like to convert this string to plain ascii (using some lookup
table for latin2)
to get
-Ukazka_moznosti _vyuziti_progra mu_OpenJUMP_v_S OA
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.nor malize 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**********@g mail.com>, 2007-11-27:
I have unicode string (or better say latin2 encoding) containing
non-ascii characters, e.g.

s = "Ukázka_možnost i_využití_progr amu_OpenJUMP_v_ SOA"

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

to get

-Ukazka_moznosti _vyuziti_progra mu_OpenJUMP_v_S OA
You may try python-elinks
<http://freshmeat.net/projects/python-elinks/>:

>>import elinks
print "Ukázka_mo\236n osti_vyu\236ití _programu_OpenJ UMP_v_SOA".deco de('Windows-1250').encode(' ASCII', 'elinks')
Ukazka_moznosti _vyuziti_progra mu_OpenJUMP_v_S OA
--
Jakub Wilk
Nov 28 '07 #5
On Nov 27, 5:08 pm, John Machin <sjmac...@lexic on.netwrote:
On Nov 28, 8:45 am, kyoso...@gmail. com wrote:


On Nov 27, 3:35 pm, Martin Landa <landa.mar...@g mail.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žnost i_využití_progr amu_OpenJUMP_v_ SOA"
I would like to convert this string to plain ascii (using some lookup
table for latin2)
to get
-Ukazka_moznosti _vyuziti_progra mu_OpenJUMP_v_S OA
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.nor malize 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
505
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 = txtItemDesc.Text.ToCharArray Dim pos As Integer While pos < chrArr.Length Dim c As Char MsgBox(Asc(chrArr(pos)) & " " & chrArr(pos)) pos = pos + 1
6
2038
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 convert that to decimal I would get 12154. I can't figure out how to concatenate? my hex values together if that makes any sense? Any pointers would be greatly appreciated!
4
2439
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 unfortunate that i have to walk via System.String to do that. For instance, from an integer of value 123, i want:
3
276695
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
34151
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 Encoding.Convert, but that needs byte arrays. Thanks, /Ger
30
3323
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 string to all lowercase? (I know how to do it manually, but in the interests of portability...) Thanks Steve
0
3669
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 Country/region: United States of America
5
9043
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) { if (null == array || 0 == array.Length) { throw new NullReferenceException();
4
2244
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 this new user tries to login, a new hash will be created for the given password and compared to the stored hash. I guess this is quite common.
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10599
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10346
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6863
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.