Home > Language Reference > String Management Functions > ExtractBetween$

ExtractBetween$

The ExtractBetween$ function extracts text between two strings.

Usage

Used in Capture operations. For example, you capture the contents of a web page using GetPageSource$ function and you extract only the text you want.  

Syntax

var$=ExtractBetween$(<source_string>, <start_string>,included|excluded, <end_string>,included|excluded)

Parameters

<source_string>, string, text to manipulate.

<start_string>, string. The extraction starts from this string. If this string is an empty string ("") or is not found, the extraction starts from the beginning of <source_string>.

included|excluded, keyword. If included is used, the extraction starts from <start_string> and includes <start_string>. If excluded is used, the extraction starts just after <start_string>.

<end_string>, string. The extraction finishes at this string. If <end_string> is an empty string ("") or is not found, the extraction finishes at the end of <initial_string>.

included|excluded, keyword. If included is used, the extraction finishes at the end of <end_string> and includes <end_string>. If excluded is used, the extraction finished just before <end_string>

Return value

var$, string, result of the extraction. If the function fails, the function returns an empty string (an empty string is "").

Remarks

Generate the ExtractBetween$ syntax using its wizard: in the Language pane of the WinTask Editor, double-click the ExtractBetween$ function name to start the wizard (if the Language pane is not displayed, press F4 or select Insert/Statement menu).

The extraction process is case sensitive.

The extraction is done between the first occurrence of <start_string> and the first occurrence of <end_string>.

If <start_string> and <end_string> are identical, the extracted result is the string between the first and the second occurrence of <start_string>.

See also

Asc
Chr$
Encrypt
InStr
InStrRev
LCase$
Left$
Len
LTrim$
Mid$
Replace$
Right$
RTrim$
SplitIntoArray
Str$
Trim$
UCase$
Val

Examples

Initialstring$="Automate any combination of tasks, whether Web or Windows applications"
Startstring$="any"
Endstring$="Web"
a$=ExtractBetween$(initialstring$,startstring$,included,endstring$,included)
' a$ contains : "any combination of tasks, whether Web"

a$=ExtractBetween$(initialstring$,startstring$,included,endstring$,excluded)
' a$ contains : "any combination of tasks, whether"

a$=ExtractBetween$(initialstring$,startstring$,excluded,endstring$,included)
' a$ contains : " combination of tasks, whether Web"

Initialstring$="Automate any combination of tasks, whether Web or Windows applications"
Startstring$=""
Endstring$="Web"
a$=ExtractBetween$(initialstring$,startstring$,included,endstring$,included)
' a$ contains : "Automate any combination of tasks, whether Web"

Initialstring$="Automate any combination of tasks, whether Web or Windows applications"
Startstring$="any"
Endstring$="nothing"
a$=ExtractBetween$(initialstring$,startstring$,included,endstring$,included)
' a$ contains : "any combination of tasks, whether Web or Windows applications"

' Some examples at boundaries
a$=ExtractBetween$("abc def ghi £test abc >test","£",included,"£test",included)
' a$ contains : "£test abc >test"

a$=ExtractBetween$("abcabctt","abc",excluded,"abc",included)
' a$ contains : "abc"

a$=ExtractBetween$("abcabctt","",excluded,"abc",excluded)
' a$ contains : "" (empty string)

a$=ExtractBetween$("ttabcabc uu","abc",excluded,"",excluded)
' a$ contains : "abc uu"