[Overview][Constants][Types][Procedures and functions][Index] Reference for unit 'LazStringUtils' (#lazutils)

StringCase

Emulates the CASE .. OF statement for string values.

Declaration

Source position: lazstringutils.pas line 101

function StringCase(

  const AString: string;

  const ACase: array of string

):Integer; overload;

function StringCase(

  const AString: string;

  const ACase: array of string;

  const AIgnoreCase: Boolean;

  const APartial: Boolean

):Integer; overload;

Arguments

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.

Arguments

AString

  

Value compared to the array elements in ACase.

ACase

  

Case constants which determine the selected case in the return value.

AIgnoreCase

  

True if case is ignored in the comparison.

APartial

  

True is a partial match at the start of a selector is considered a match.

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

CompareText


Version 4.0 Generated 2025-05-03 Home