1

I am trying to code something that removes any unwanted characters from my PC's clipboard, example: a-3-g-6-x to turn into a3g6x, or "H 3 x 8 l" into "H3x8l". Any help would be greatly appreciated.

Killboe
  • 19
  • 2
  • You could create a list with all unwanted characters and then iterate over that list and use `replace()` method in your string for each character. But you will have to be more specific in your question. – Vasilis G. Jan 26 '20 at 18:09
  • 1
    Can you be more specific about what the issue is? – AMC Jan 26 '20 at 18:09
  • How you access the paste buffer depends on your OS. her's an answer for windows. https://stackoverflow.com/questions/101128/how-do-i-read-text-from-the-windows-clipboard-from-python – kpie Jan 26 '20 at 18:10

1 Answers1

0

you can use win32clipboard part of pywin32

import win32clipboard


# get clipboard data
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()

unwanted = [" ", "~"]
data = [s for s in data of s not in unwanted]

# set clipboard data
win32clipboard.OpenClipboard()   
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(data)
win32clipboard.CloseClipboard()
Sneftel
  • 40,271
  • 12
  • 71
  • 104
Yoav Glazner
  • 7,936
  • 1
  • 19
  • 36