Forum Moderators: open

Message Too Old, No Replies

Converting ACSII to UTF-8

A quick python script to convert for XML files

         

Demaestro

11:14 pm on Nov 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Recently I started to create dynamic RSS feeds for many of my sites, but I found that almost all of the data I was returning had illegal characters, everytime I would replace one and another would crop up.

I wrote a simple script in python that converts ACSII to UTB-8. You pass it a string and it will convert. Just wanted to share.

This should work in Python 2.1 and up:
************************
##parameters=ascii_string=''

unicode_string = u''

for thisIndex in range(len(ascii_string)):
unicode_string = unicode_string + unichr(ord(ascii_string[thisIndex]))

return unicode_string
************************

Hope this helps anyone and may be translated to PERL with ease (I am guessing)