Convert string into numerical data

Asked by MPE

Hi there,

I want to do the following:
1 Select a bit of text (it is actually a number) from a datafield within a browser (not a problem in sikuli).
2 Convert the string value into numerical data
3 Add +1 to the new value
4 Paste the new value

My problem is that I am stuck on step 2. What is the easiest way to go about? I'm not even sure if Sikuli can do this.

Many thanks in advance!

MPE

UPDATE:
Ok, so I've found answers to similar question using "number = int(Region.text(calcUpperLeft))"
The problem is, however, that I have no idea how to define a region, and there really are no instructions or tutorials online. Help is much appreciated.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
MPE
Solved:
Last query:
Last reply:
Revision history for this message
masuo (masuo-ohara) said :
#1

#convert strings to numeric
str_x = "10"
num_x = int(str_x)
num_y = num_x + 1

#convert numeric to strings
str_y = str(num_y)

#confirm type of variable
try:
    import builtins
except ImportError:
    import __builtin__ as builtins

print "num_y:",builtins.type(num_y)
print "str_y:",builtins.type(str_y)

Revision history for this message
MPE (maartenpelgrim) said :
#2

Hi Masuo,

That helped enormously, thank you very much!

Only thing that is missing in your explanation is how to get content from the clipboard, which I found out myself:

str_x = App.getClipboard()

After which you can just follow the steps you provided. Thanks again!