Home > Back-end >  Best way to delete LRO and RLO characters in Python
Best way to delete LRO and RLO characters in Python

Time:02-11

Is there any elegant solution or best practice how to remove RLO and LRO characters?

Explanation of my problem: I get/parse ‭400 000‬ string from the website. I need this string convert into integer type (just 400000 number value).

Any ideas how to elegantly remove this characters? (‭ and ‭)

Thanks!

//Update:

capacity_value = capacity_value.encode('ascii', 'ignore').decode().replace(" ", "")

(encode() and decode() functions works but I don't like it. Is there any better solution in this case?)

CodePudding user response:

The str type has a translate method which can be use to replace or remove characters. Here if you want to remove space, RLO and LRO, you could do:

transtable = str.maketrans('', '', ' \u202d\u202c')
capacity_value = capacity_value..translate(transtable)
  • Related