Reputation: 3386
I'm working with an api which returns some data in the form of 01234⇒56789
. Sometimes this data has only numbers which is not a problem but sometimes it returns ⇒
character. As I have to automate the filtering process of selecting the number after the arrow (non-ascii character) I have to know when the characters contains a non-ascii character.
I used decode(utf-8)
and it returns u'01234\u21d256789'
. I tried split('\u21d2')
but the string is not splitting. Any help is appreciated.
Upvotes: 0
Views: 753
Reputation: 17455
python3:
>>> s = "01234⇒56789"
>>> s
'01234⇒56789'
>>> s.split("⇒")
['01234', '56789']
python2:
>>> s = u"01234⇒56789"
>>> s.split(u"⇒")
[u'01234', u'56789']
the key point in Python2 is to specify that you deal with an unicode string. In Python3 strings are unicode by default and there's bytes type
Upvotes: 1