Re: Is there a string function to trim all non-ascii characters out of a string



On Dec 31, 1:20 pm, "silverburgh.me...@xxxxxxxxx"
<silverburgh.me...@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.

Use this function --

def omitNonAscii(nstr):
sstr=''
for r in nstr:
if ord(r)<127:
sstr+=r
return sstr
.



Relevant Pages

  • TOC of Python Cookbook now online (was Re: author index for Python Cookbook 2?)
    ... Processing a String One Character at a Time ... Finding a File on the Python Search Path ... Constructing Lists with List Comprehensions ... Looping over Items and Their Indices in a Sequence ...
    (comp.lang.python)
  • Re: =?ISO-8859-15?Q?Objektrepr=E4sentation_in_einem_Python?= =?ISO-8859-15?Q?-In
    ... Python 1.4 hat zwar ein uniformes Typsystem, Exemplare sind aber nur nur eine Art von Python-Objekt, will sagen, nicht jedes Ding hat eine Klasse. ... Called when an attribute lookup has not found the attribute in the usual places (i.e. it is not an instance attribute nor is it found in the class tree for self). ... Das einzige Element von None könnte null sein, Integer und String sind klar. ...
    (de.comp.lang.java)
  • Re: =?ISO-8859-15?Q?Objektrepr=E4sentation_in_einem_Python?= =?ISO-8859-15?Q?-In
    ... Exemplare von Klassen. ... Einzig vom Anwender definierte Klassen können Exemplare haben. ... wirklichen Grund sich an die Hierarchie von Python halten zu müssen. ... Wenn ich es richtig verstanden habe, dann ist es in Python möglich einem String eine neue Funktion zu geben, vielleicht sogar eine alte zu ersetzen. ...
    (de.comp.lang.java)
  • Re: Unrecognized escape sequences in string literals
    ... the string literal doesn't change this basic truth. ... are left in the string unchanged, i.e., the backslash ... expect that if Python had always behaved the way that C++ ... It's a legal escape sequence that maps to ...
    (comp.lang.python)
  • Re: python coding contest
    ... Claudio Grondi wrote: ... Before that I want to thank the originators of the contest and especially the participants for providing insight into the techniques they have used. ... that it would be a nice thing to have in Python a function able to convert values from binary string to an integer representation as in my eyes both in case of long integer values are more or less the same thing/object. ...
    (comp.lang.python)