R. E. Cook
RunningShoes Library for WinRunner
Custom WinRunner Functions
and Utilities, to Your Specs
A Random Collection of WinRunner Solutions
Creating DLLs for WinRunner
(Mercury Interactive's Worldwide Users Conference 2000)
R. E. Cook
SubstrAfter(), SubstrBefore(), SubstrBetween(),
FindLast(), FindWhich(), FindFromRight(),
In WinRunner without RunningShoes, capturing a substring from a source string
can be a breeze or a nightmare, depending on how much we know about the
If we know the exact position and length of a substring within the source
string, WinRunner makes it easy to capture the substring:
# Capture the last name. It starts in position 21, and is 20 characters long.
last_name = substr(source, 21, 20);
Unknown position, delimited
RunningShoes contains several functions designed to make it easy to capture
substrings when the source string is not so rigidly arranged. If we know what
characters come before and after the desired substring, we can find the
substring by finding those characters that delimit the substring.
If the delimiter characters are unique, we can find the
substring easily using RunningShoes's Substr__() functions.
For example, we are looking through an HTML file for the page title. We know
that in HTML, the title is between the tags "<TITLE>" and
"</TITLE>", so we can use those tags as delimiters:
# Define the delimiters
delim_1 = "<TITLE>";
delim_2 = "</TITLE>";
# With RunningShoes, we capture the title substring with a single line:
title = SubstrBetween(source_code, delim_1, delim_2);
Without RunningShoes, we can still find the substring in a
roundabout way. Here's the code we saved by using RunningShoes.
Two identical delimiters
If the substring is delimited by the same characters, SubstrBetween() will
still find it as long as those delimiters do not appear elsewhere in the
Example: the id_string contains "first name, last name, age".
# The last name is between commas, no other commas appear in the string:
last_name = SubstrBetween(id_string, ",", ",");
Multiple non-unique delimiters
If the substring is delimited by characters that appear elsewhere in the
string, SubstrBetween() won't work. We must first find which delimiters we want.
Use the various Find__() functions to determine the position of the substring.
This is a case where RunningShoes really makes our lives (or at least our
Example: id_string contains "first name, middle name, last name, age,
The last name is between the 2nd and 3rd commas (comma followed by space).
# Define delimiter (comma space) and determine its length.
delimiter = ", ";
len_delim = length(delimiter);
# Find the 2nd comma.
start = FindWhich(id_string, delimiter, 2);
# Move the starting position past the comma.
start += len_delim;
# Find the 3rd comma.
end = FindWhich(id_string, delimiter, 3);
# Capture the last name between the 2nd and 3rd commas.
last_name = substr(id_string, start, end - start);
Without RunningShoes, it's a
challenge. Here's 24 lines of code we would have to write, debug, and maintain
to accomplish the same thing as the 6 lines above. (It's in a text file to avoid
browser format mangling.)
Updated 17 January 2005