Using region.text() appends extra newline character at the end

Asked by Alan Dale

Hi,

I've noticed this issue when trying to capture and print text from a region. Possible bug or just maybe i'm doing something wrong. The issue anyway is this:

I'm capturing text from a region, printing out the text in either notepad or a text entry box, at the end of the captured text an enter command is being sent through. This is causing me problems as I need to concatenate the captured text with another string, but before the string is joined with another the enter command is sent through and moves onto a new line or submits the text entry box. As i'm wanting to enter this into a text box, after i type the captured text it is then submitted due to this rogue enter key before my string is joined with another.

Simply doing this in notepad shows what is happening.

reg = Region(Region(316,335,339,24))
myText = reg.text()
wait(2)
openApp ("C:\\Windows\\system32\\notepad.exe")
wait(2)
type (myText)

The text that is captured and pasted is exactly what i am looking for but without this enter command at the end.

Any advice or a possible workaround would be great!

Cheers
Alan.

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
Best RaiMan (raimund-hocke) said :
#1

The "Enter-Command" is a newline character, that is appended to your text read from the region by the reg.text() (this is one of the many oddities of the current version of the OCR feature).

To get rid of it:
myText = reg.text().strip()

the string function strip() removes all leading and trailing whitespace characters.

BTW: the first wait(2) is not needed

Revision history for this message
Alan Dale (adale3g) said :
#2

Thanks RaiMan, that solved my question.

Revision history for this message
Alan Dale (adale3g) said :
#3

Thanks for the quick turnaround

So simple! :) Working exactly as i want it too now

Thanks again!