R. E. Cook
Contact Us 

Dr. Cook

RunningShoes Library for WinRunner 

Custom WinRunner Functions 
and Utilities,
to Your Specs

A Random Collection of WinRunner Solutions

Creating DLLs for WinRunner 
"DLLs Demystified" 
(Mercury Interactive's Worldwide Users Conference 2000)

Find the index of any specified occurrence of a character in a string.


In WinRunner, it's easy to find the index of the first occurrence of a character in a string:

## Find the position of the first comma in the string.
position = index(text, ",");

If we need the position of, say, the 13th comma in a comma-delimited string, we have to put the index() statement in a loop, dropping the part of the string already searched with the previous index() statement.  

The function IndexMulti() finds any specified occurrence of the character in a string in which the character appears multiple times:

# Find the position of the 13th comma.
thirteenth_comma = IndexMulti(text, ",", 13);

The code for both versions is in a text file to avoid the format mangling that browsers tend to do to normal pages. View IndexMulti.txt.

Top of  This Page | R. E. Cook Home Page

Copyright R. E. Cook Consulting, 2000 - 2011.
All rights reserved.

The site is designed to look best when viewed with Internet Explorer 5.0 - 8.0. Results with other browsers will probably deviate from what is intended.

NOTE: This website refers to registered trademarks and service marks that are owned by other companies, including Mercury Interactive, WinRunner, TestDirector, TSL, Microsoft, Windows.