StringCase function
Emulates the CASE .. OF statement for string values.
Declaration
function StringCase(const AString: string;
const ACase: Array of string = string): Integer
; overloadArguments
AString | Value compared to the array elements in ACase. |
ACase | Case constants which determine the selected case in the return value. |
Function result
Ordinal position for the selected case constant, or -1 when a match is not found.
Description
StringCase is an overloaded
Integer function used to
emulate the Pascal
CASE .. OF statement.
AString contains the value compared to the elements in the
ACase array.
ACase is an array of String values with the case constants used in
the comparison to
AString.
AIgnoreCase indicates whether case is significant when AString is
compared to elements in ACase. When set to
False (the default), case
is significant. When set to
True, a case-insensitive comparison is
performed for the values using the CompareText routine.
APartial indicates whether the value in AString can be a partial
match for the value in an array element. When set to
False, AString
must match the array element exactly to be considered a match. When set to
True, any value in ACase which
starts with the value in AString
is considered a match.
The return value contains the ordinal position for the element in ACase which matches the value in AString. The return value is -1 if a match was not found for the value in AString.
// var SelOpt: Integer;
// returns 2
SelOpt := StringCase('Charlie', [ 'Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo' ]);
// returns 3 for case-insensitive partial match
SelOpt := StringCase('del', [ 'Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo' ], True, True);
// returns -1
SelOpt := StringCase('foo', [ 'Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo' ]);See also
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
