How do I use this sub routine?

Hi there,

I have done some digging around online and I’ve found this subroutine that could be mega useful to me. I haven’t used sub routines very much so I have a pretty basic question.

I have a block of text. I run this sub which successfully returns the text that appears between the two [ ] markers.

My question is - how do i save the result it returns to a variable?! This is probably really super simple but i’m stumped!

Thanks in advance for any help!
Adam

To use it, copy text to clipboard and run the script below.

Heres some sample text to pass through it:

The sub im trying to use is this:

set idGet to the clipboard


extractBetween(idGet, "Encrypt: [", "]")
---- The handler ----  
to extractBetween(SearchText, startText, endText)
	set tid to AppleScript's text item delimiters -- save them for later.  
	set AppleScript's text item delimiters to startText -- find the first one.  
	set endItems to text of text item -1 of SearchText -- everything after the first.  
	set AppleScript's text item delimiters to endText -- find the end one.  
	set beginningToEnd to text of text item 1 of endItems -- get the first part.  
	set AppleScript's text item delimiters to tid -- back to original values.  
	return beginningToEnd -- pass back the piece.
end extractBetween

Hi,

It’s really super simple , just assign the result of the handler to the variable:

set thisIsTheTextINeed to extractBetween(idGet, "Encrypt: [", "]")

Awesome! Thanks!