Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove zero width space unicode character from Python string

Tags:

I have a string in Python like this:

u'\u200cHealth & Fitness' 

How can i remove the

\u200c 

part from the string ?

like image 755
V.Anh Avatar asked Sep 11 '17 11:09

V.Anh


People also ask

How do I remove Unicode characters from a string in Python?

In python, to remove Unicode character from string python we need to encode the string by using str. encode() for removing the Unicode characters from the string.

How do you remove zero width space from a string?

To remove zero-width space characters from a JavaScript string, we can use the JavaScript string replace method that matches all zero-width characters and replace them with empty strings. Zero-width characters in Unicode includes: U+200B zero width space. U+200C zero-width non-joiner Unicode code point.

What is u200c in Python?

The \u200c character is ZERO WIDTH NON-JOINER.


1 Answers

You can encode it into ascii and ignore errors:

u'\u200cHealth & Fitness'.encode('ascii', 'ignore') 

Output:

'Health & Fitness' 
like image 189
Arount Avatar answered Oct 03 '22 23:10

Arount