Search code examples
pythonpython-3.xpython-re

How to split only "±" in a python string?


How to convert the "±" into "+-" or vice versa in a python string?

For example I have this string 18.1±0.3% hemolysis at 50µM and only want to split ± in this string +-.


Solution

  • This is not splitting. You call it so, because, graphically, it looks that way. But there is not other relation (other than appearance in your fonts) between '±' and '+' and '-'.

    So what you are looking for, is just good, old, pattern search and replace.

    mystring.replace('±', '+-')