Help With Extracting Text

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

Help With Extracting Text

Post by fightcancer » Mon Oct 13, 2008 5:30 am

I'm having a hard time getting the Level stored in my var "strText" which is captured using the GetTextInRect command. The actual value stored in strText is displayed below. I copied this excerpt from the log file of the macro after doing a var dump.

(I'm requesting help getting the value 83 from the string called strText.)
10/13/2008 00:06:52:277 - STRTEXT= Fightcancer, Level
83

10/13/2008 00:06:52:277 - KSRTGETTEXTINRECT=1
I included the line after the line in question merely to demonstrate that the value of strText includes multiple line breaks and spaces. The problem is I don't know how many lines or spaces the captured text will include when I capture it. Also, the level can be 1, 2 or 3 digits.

Thanks!

fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

Post by fightcancer » Mon Oct 13, 2008 7:41 am

Nm. I just found the "System Variables" and should be able to test each character in strText after "Level" to see if it's a space, tab, LF, CR, etc. The remaining characters should be my level.

EDIT: Got it to work.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Oct 13, 2008 4:48 pm

Rather than testing each character,, here are a few other approaches.

1. You could use Position to find level, then use MidString to capture the level value and remove leading spaces.

Code: Select all

Let>test=10/13/2008 00:06:52:277 - STRTEXT= Fightcancer, Level  83 
Position>Level,%test%,1,Start
Let>Begin=%Start%+5
MidStr>%test%,%Begin%,20,Value
StringReplace>%Value%,%space%,,Value
MessageModal>The value is %Value%
----------------------------------------------------------
2. If the value will always be two digits, then this would work:

Code: Select all

Let>test=10/13/2008 00:06:52:277 - STRTEXT= Fightcancer, Level  83 
Length>%test%,strLength
Let>Begin=%strLength%-2
MidStr>%test%,%Begin%,2,Value
MessageModal>The level is %Value%
----------------------------------------------------------
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

fightcancer
Macro Veteran
Posts: 260
Joined: Fri Apr 15, 2005 8:32 am

Post by fightcancer » Wed Oct 15, 2008 9:45 pm

Bob Hansen wrote:1. You could use Position to find level, then use MidString to capture the level value and remove leading spaces.
I like this approach a lot. I wish I had known about StringReplace earlier. Even though I would've had to use multiple StringReplace commands, it would've been easier than testing each character. (The strText frequently had at least one LF/CR/CRLF.) :) thanks!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts