2015-09-06 6 views
6

मैं थोड़ी देर के लिए इस के साथ संघर्ष कर रहा हूं। मैं HTML पर स्ट्रिंग लिखने की कोशिश कर रहा हूं लेकिन प्रारूप को साफ़ करने के बाद प्रारूपों के साथ समस्याएं हैं। यहाँ एक उदाहरण है:पायथन एचटीएमएल एन्कोडिंग xc2 xa0

paragraphs = ['Grocery giant and household name Woolworths is battered and bruised. ', 
'But behind the problems are still the makings of a formidable company'] 

x = str(" ") 
for item in paragraphs: 
    x = x + str(item) 
x 

आउटपुट:

"Grocery giant and household name\xc2\xa0Woolworths is battered and\xc2\xa0bruised. 
But behind the problems are still the makings of a formidable\xc2\xa0company" 

वांछित उत्पादन:

"Grocery giant and household name Woolworths is battered and bruised. 
But behind the problems are still the makings of a formidable company" 

मैं आशा करती हूं कि आप को समझाने के लिए कि ऐसा क्यों होता है और मैं कैसे ठीक कर सकते हैं कर रहे हैं। अग्रिम में धन्यवाद!

+2

क्या आपने अपनी स्रोत स्ट्रिंग में असामान्य यूनिकोड व्हाइटस्पेस की जांच की है? –

उत्तर

14

\ xC2 \ xa0 मतलब है 0xC2 0xA0

गैर-ब्रेकिंग स्पेस

यह UTF-8 एनकोडिंग में अदृश्य नियंत्रण चरित्र की तरह है तथाकथित है। इसके बारे में अधिक जानकारी विकिपीडिया की जांच करें: https://en.wikipedia.org/wiki/Non-breaking_space

मैंने प्रश्नों में चिपकाया है और अपेक्षित आउटपुट प्राप्त किया है।

+5

धन्यवाद। यह ठीक करता है। मैंने बनाया: x.replace ("\ xc2 \ xa0", "") –

संबंधित मुद्दे