JCL Help:StrIndex@AnsiString@array of AnsiString@Boolean

From Project JEDI Wiki
Jump to navigationJump to search


Summary

Returns the index of a string in an array of strings.


Pascal

 function StrIndex(const S: string; const List: array of string; CaseSensitive: Boolean = False): SizeInt;
function StrIndex(const S: AnsiString; const List: array of AnsiString; CaseSensitive: Boolean = False): SizeInt;


Parameters

Parameters Description
const S: string The string to test.
const List: array of string Array of strings to search in.


Return Value

If the supplied string exists in the List array the zero based index of the position at which it appears is returned. If the string doesn't exist in the array -1 is returned. Note that the string comparison is case insensitive but is based on the current locale (ie it uses AnsiSameText).


Description

StrIndex returns the index into the List array at which S is positioned. This is particularly useful to create a case statement based on string labels. For example: case StrIndex(S, ['zero', 'one', 'two']) of 0: // handle case where S = 'zero' 1: // handle case where S = 'one' 2: // handle case where S = 'two' else // end;


About

Unit

JclAnsiStrings


Donator

Anthony Steele


Contribute to this help topic

This documentation wiki is based on the collaborative effort of Project JEDI users. Your edits are welcome in order to improve documentation quality: edit this page