Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Unicode char replace

Reply
Thread Tools

Unicode char replace

 
 
DiMar
Guest
Posts: n/a
 
      02-12-2008
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','»')

u'Macworld \xbb Jobs 1 - Twitter 0'

2.
>>> import cgi
>>> string2 = cgi.escape(string).encode("ascii", "xmlcharrefreplace")
>>> string2

'Macworld » Jobs 1 - Twitter 0'

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

Any idea?

Thanks!
 
Reply With Quote
 
 
 
 
Martin v. L÷wis
Guest
Posts: n/a
 
      02-12-2008
> string = u'Macworld ╗ Jobs 1 - Twitter 0'
>
>
> None of them gives me 'Macworld » Jobs 1 - Twitter 0'
>
> Any idea?


So I assume you *want* it to produce ». May I ask why?
I really recommend that you use » instead.

In any case, you need to define your own error handler, such as
the one in

http://herlock.com/ob/pythoncb/05960...1-sect-23.html

HTH,
Martin
 
Reply With Quote
 
 
 
 
Michael Goerz
Guest
Posts: n/a
 
      02-12-2008
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','»')

> u'Macworld \xbb Jobs 1 - Twitter 0'

How about this?
string.replace(u'\xbb', u'»')
 
Reply With Quote
 
DiMar
Guest
Posts: n/a
 
      02-12-2008
> May I ask why?

Of course! I have to find that string into a list of strings. This
list includes one, using »
Thanks!
 
Reply With Quote
 
DiMar
Guest
Posts: n/a
 
      02-12-2008
On 12 Feb, 22:11, Michael Goerz <(E-Mail Removed)4ward.com>
wrote:

> How about this?
> string.replace(u'\xbb', u'&raquo;')


Thanks, it works!!!

DiMar
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help for Unicode char and Unicode char based string in Ruby Chirag Mistry Ruby 6 02-08-2008 12:45 PM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
The difference between char a[6] and char *p=new char[6] ? wwj C Programming 24 11-07-2003 05:27 PM
the difference between char a[6] and char *p=new char[6] . wwj C++ 7 11-05-2003 12:59 AM



Advertisments