Re: Is there a string function to trim all non-ascii characters out of a string
- From: Duncan Booth <duncan.booth@xxxxxxxxxxxxxxx>
- Date: 31 Dec 2007 10:24:33 GMT
"silverburgh.meryl@xxxxxxxxx" <silverburgh.meryl@xxxxxxxxx> wrote:
Hi,
Is there a string function to trim all non-ascii characters out of a
string?
Let say I have a string in python (which is utf8 encoded), is there a
python function which I can convert that to a string which composed of
only ascii characters?
Thank you.
Yes, just decode it to unicode (which you should do as the first thing for
any encoded strings) and then encode it back to ascii with error handling
set how you want:
'?42's = '\xc2\xa342'
s.decode('utf8').encode('ascii', 'replace')
'42's.decode('utf8').encode('ascii', 'ignore')
'£42's.decode('utf8').encode('ascii', 'xmlcharrefreplace')
.
- References:
- Is there a string function to trim all non-ascii characters out of a string
- From: silverburgh.meryl@xxxxxxxxx
- Is there a string function to trim all non-ascii characters out of a string
- Prev by Date: online dating with modern girs near you'r place
- Next by Date: at what complexity, a comparison fails ?
- Previous by thread: Re: Is there a string function to trim all non-ascii characters out of a string
- Next by thread: Re: Is there a string function to trim all non-ascii characters out of a string
- Index(es):
Relevant Pages
|