2014-10-02 40 views
2

這裏是代碼:我不能擺脫 xa0在這個字符串中使用python?

shipping_info = u'Expedited (2-3 Bus. Days)\xa0($17.99)' 

我不能讓它使用像用替換法更換\ XA0。

這裏是我的嘗試:

x.replace('\\xa0', ' ') 
x.replace(')\xa0(', " ") 
x.replace(unichr(160), " ") 
+1

記住'replace'不起作用原地的,你必須分配結果。 'x = x.replace(...)'。 – 2014-10-02 14:53:38

回答

3

使用Unicode文本指定u'\xa0'

>>> shipping_info = u'Expedited (2-3 Bus. Days)\xa0($17.99)' 
>>> shipping_info.replace(u'\xa0', u' ') 
u'Expedited (2-3 Bus. Days) ($17.99)' 
+0

'u'...''v.s. ''...'' – 2014-10-02 14:50:13

+0

你在ipython中試過這個嗎?我試過這個..不工作..?你可以試試嗎? – slopeofhope 2014-10-02 15:04:08

+0

@slopeofhope,當然,我嘗試過。 http://asciinema.org/a/12634 – falsetru 2014-10-02 15:06:12

相關問題