Jump to content
Macro Express Forums

Set String From Window Title & Just Keep The First Word


creztor

Recommended Posts

Ok, this is what I am trying to do. I want to set a string variable to the window title that is shown in IE. So the window title may be "welcome everyone". I believe the set string to window title variable function will do this, but I only want to keep the first word. The window title will always vary, depending on the site I am visiting, but I just want to keep the first word and delete everything else. Some examples of titles

 

welcome john

hello there

jump now

lets just do it

scream for joy everyone

 

They aren't the exact titles but you can see the length varies, but I just need to keep the first word and delete all the others. Can anyone help me do this please? :)

Link to comment
Share on other sites

Variable Set String T1 [from topmost window title]

Variable Modify String T1 append " " (to assure that there is at least one blank at the end of the string variable T1)

Variable Set String T2 = "" (null)

Variable Set String T3 = "" (null)

 

Repeat Start 999 times [with counter beginning at 1 placed into variable N1]

Variable Modify String T1 copy 1 byte of text from T1 to T2 starting at position N1

If T2=" "

Repeat Exit

End If

Variable Modify String append T2 to T3

Repeat End

 

The above repeat-loop will break when the first blank space is found in variable T1, and the word found up to that

point will be in T3.

Link to comment
Share on other sites

Here is another approach.

// Get the Window Title
Variable Set String %T1% from Window Title
// Trim to remove spaces at beginning or end of the window title ... just in case
Variable Modify String: Trim %T1%
// Get position of the first space in T1
Variable Set Integer %N1% from Position of Text in Variable %T1%

// Do the following if at least one space was found
If Variable %N1% > 0
 // Decrement to skip copying the space
 Variable Modify Integer: Dec (%N1%)
 // Copy from beginning of Window title in T1 up to the character prior to the space
 Variable Modify String: Copy Part of %T1% to %T1%
End If

Copy this and paste it into your macro:

<REM2:Get the Window Title><TVAR2:01:06:><REM2:Trim to remove spaces at beginning or end of the window title ... just in case><TMVAR2:01:01:00:000:000:><REM2:Get position of the first space in T1><IVAR2:01:13:1: ><REM2:><REM2:Do the following if at least one space was found><IFVAR2:2:01:4:0><REM2:Decrement to skip copying the space><NMVAR:09:01:0:0000001:0:0000000><REM2:Copy from beginning of Window title in T1 up to the character prior to the space><TMVAR2:10:01:01:001:N01:><ENDIF>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...