Unicode char replace

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DiMar

    Unicode char replace

    Hi all,

    I have this unicode string:

    string = u'Macworld » Jobs 1 - Twitter 0'

    and I want to replace the '»' (aka \xbb) char to '&raquo'.
    I've tried 2 ways:

    1.
    >>string2 = string.replace( '\\xbb','&raquo ;')
    u'Macworld \xbb Jobs 1 - Twitter 0'

    2.
    >>import cgi
    >>string2 = cgi.escape(stri ng).encode("asc ii", "xmlcharrefrepl ace")
    >>string2
    'Macworld » Jobs 1 - Twitter 0'

    None of them gives me 'Macworld » Jobs 1 - Twitter 0'

    Any idea?

    Thanks!
  • Michael Goerz

    #2
    Re: Unicode char replace

    DiMar wrote, on 02/12/2008 09:54 PM:
    Hi all,
    >
    I have this unicode string:
    >
    string = u'Macworld » Jobs 1 - Twitter 0'
    >
    and I want to replace the '»' (aka \xbb) char to '&raquo'.
    I've tried 2 ways:
    >
    1.
    >>>string2 = string.replace( '\\xbb','&raquo ;')
    u'Macworld \xbb Jobs 1 - Twitter 0'
    How about this?
    string.replace( u'\xbb', u'»')

    Comment

    • DiMar

      #3
      Re: Unicode char replace

      May I ask why?

      Of course! I have to find that string into a list of strings. This
      list includes one, using »
      Thanks! :)

      Comment

      • DiMar

        #4
        Re: Unicode char replace

        On 12 Feb, 22:11, Michael Goerz <newsgroup898s. ..@8439.e4ward. com>
        wrote:
        How about this?
        string.replace( u'\xbb', u'&raquo;')
        Thanks, it works!!!

        DiMar

        Comment

        Working...