get lines (not characters) from clipboard

Asked by fernando gandini

hi guys,

there is any way to get entire lines from Evn.clipboard ?

cause when i try this:

//copy - "hello world"

xReader = Env.getClipboard()
for line in xReader:
    print line

i get every character in a new line, like this:
h
e
l
l
o
....
but i need to get the entire line....can any one help me?
tanks

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Jacob Dorman (japhezbemeye) said :
#1

Is this what you're trying to do?

xReader = Env.getClipboard()
    print xReader

I'm pretty sure the dynamic typing is interpreting your variable called "line" as a character, and just printing each character in the string "xReader".

Revision history for this message
Jacob Dorman (japhezbemeye) said :
#2

Oops, disregard the space before print, it should be:

xReader = Env.getClipboard()
print xReader

Revision history for this message
Best RaiMan (raimund-hocke) said :
#3

xReader = Env.getClipboard()
for line in xReader:
    print line

lets look at it step by step:
- xReader contains a string as result from Env.getClipboard()
- a string is a list of characters
- for x in aList: loops through the list setting x to every list element one after the other

conclusion:
since xReader is a list of characters, the loop produces one printout for each character.

If you expect "lines" to be in your string coming from the clipboard, they should have some line breaks (e.g. \n), that can be used to split the string into "lines":

# we expect \n as line break
xReader = Env.getClipboard()
for line in xReader.split("\n"):
     print line

will do what you want, even if it is only one line without the line break.

Revision history for this message
RaiMan (raimund-hocke) said :
#4

xReader.split("\n")
returns a list of the strings, that are separated by \n without this separator.

Revision history for this message
fernando gandini (fernando-gandini) said :
#5

hey guys, really tanks....i cant believe is that simple.
works perfect.
bye

Revision history for this message
fernando gandini (fernando-gandini) said :
#6

Thanks RaiMan, that solved my question.