German umlaut in a string.
Leszek Krupiński
leszek at php.net
Tue Aug 12 14:43:27 EDT 2003
Ship log, stardate: [-29]0729.3, Lukas Kasprowicz reports:
> Hi Folks,
>
> I have a string filled with much text converted from a tuple.
>
> when I try to do someting like this:
>
> exclusion = re.sub("\\xf6", "%F6", exclusion) # ö
> exclusion = re.sub("\\xfc", "%FC", exclusion) # ü
> exclusion = re.sub("\\xe4", "%E4", exclusion) # ä
> exclusion = re.sub("\\xdf", "%DF", exclusion) # ß
>
> it takes no effect at the string.
>
> things like:
>
> exclusion = re.sub(',', '', exclusion)
> exclusion = re.sub('\(', '', exclusion)
> exclusion = re.sub('\)', '', exclusion)
> exclusion = re.sub("'", "", exclusion)
> exclusion = re.sub(" ", "+%2D", exclusion)
> work fine.
>
> when i write the sting in a python console into a variable like:
>
> >>> test = "some\\xf6thing"
> >>> print re.sub("\\xf6", "%F6", test)
> some%F6thing
>
> I get the correct output.
It works for you?
>>> test = "some\\xf6thing"
>>> print re.sub("\\xf6", "%F6", test)
some\xf6thing
(Python 2.3)
>>> exclusion = "some\xf6thing"
>>> exclusion = re.sub("\\xf6", "%F6", exclusion)
>>> print exclusion
some%F6thing
I believe that problem is in slashes.
Leon
--
_________________________Silly is a state of mind, stupid is a way of life
/ Homepage: http://www.leon.w-wa.pl/ GPG Key @ keyserver.net
| JabberID: leafnode at jabberpl.org Real email in headers
\_ Curriculum Vitae: http://www.leon.w-wa.pl/cv.pdf _______________________
More information about the Python-list
mailing list