Splitting and Replacing - and — in a string

42 Views Asked by At

Problem Description:

I just discover that there is at least 2 types of dash actually 3 anyway. I get a list of files: result = list(desktop.glob("*.pdf")) Each line of result is a string with - and — in it (it might not be obvious here but the 2 - are different: here is the ascii code for each one: alt+045, alt+0151.

My intial goal was to split on -(alt+045) in order to do my stuff on the string. But I always add —(alt0151) in my string :-( Because the story about the two dash...

So I tried to replace all the —(alt+0151) by -(alt+045) but I was unable because the replace function doesnt seem to accept ascii code, or (it is possible) I didn't do it as it is expected.

Question:

1 / Is there a way to split on -(alt+045) and —(alt+0151)? 2 / If 1 is not possible is there a way to replace —(alt+0151) by -(alt+045) 3 / I quickly looked on internet and found nothing about Python dealing with this issue but once again I might not have looking for properly...

I tried to use split() and replace() with ascii code without success. I looking for a way to use split() on -(alt+045) AND on —(alt+0151).

0

There are 0 best solutions below