0

I'm hoping there exists a quick hack that will tell me the length of a string contained in the windows clipboard. (if it is in fact a string).

It's not for any kind of production code, and I'm not tied to any particular language.

TIA

jon
  • 5,608
  • 4
  • 26
  • 35
  • You can also do it [in vb / vba](http://stackoverflow.com/questions/5552299/how-to-copy-to-clipboard-using-access-vba). – assylias Jul 19 '12 at 13:59

2 Answers2

1

In Java:

java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
String content = (String) clipboard.getData(DataFlavor.stringFlavor);
int size = content.length();

Add additional error checking as required.

assylias
  • 310,138
  • 72
  • 642
  • 762
0

In python:

import ctypes
ctypes.windll.user32.OpenClipboard(None)
print len(ctypes.c_char_p(ctypes.windll.user32.GetClipboardData(1)).value)
ctypes.windll.user32.CloseClipboard()
jon
  • 5,608
  • 4
  • 26
  • 35