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



On Mon, 31 Dec 2007 01:09:09 -0800, John Machin wrote:

On Dec 31, 7: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?


OK, I'll bite: why do you want to throw data away?

Maybe he has to send the data to a device that can't deal with more than
7-bit ASCII.

Maybe he's sick of seeing text with "missing character" squares all over
from all the characters that his fonts can't display.

Maybe the string ends up as a file name on an operating system that
doesn't support unicode.

Or maybe he's just a curmudgeon who thinks life was better when there
were only 128 characters available.


--
Steven
.



Relevant Pages

  • Re: String prefix question
    ... along with how Python deals with this: ... characters to show for the upper 128. ... To solve this problem, Unicode was created. ... front of the string declaration ...
    (comp.lang.python)
  • Re: How to convert Infix notation to postfix notation
    ... If this is for an error message, why isn't it using stderr for its output? ... array of 15 characters, and you call this function with the limit 15 on ... Making sure that the only string I allocate and append to, ... because mulFactor in all versions must needs incorporate the functions ...
    (comp.lang.c)
  • Re: Prothon should not borrow Python strings!
    ... """It does not make sense to have a string without knowing what encoding ... same cul de sac as Python. ... Prothon_String_As_ASCII // raises error if there are high characters ... Python's split between byte strings and Unicode strings is ...
    (comp.lang.python)
  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... put them in stupid places. ... Programming is difficult (as you must surely appreciate, ... > strings will be in the range 1...1000 characters. ... impose an artificially small limit on string length." ...
    (comp.programming)
  • Re: Byte Array to String
    ... retrieved text will mismatch the original characters. ... encoding the characters. ... Dim strFileData as String ...
    (microsoft.public.dotnet.framework.aspnet)