System.SysUtils.TStringHelper.IndexOfAnyUnquoted

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function IndexOfAnyUnquoted(const AnyOf: array of Char; StartQuote, EndQuote: Char): Integer; overload;
function IndexOfAnyUnquoted(const AnyOf: array of Char; StartQuote, EndQuote: Char; StartIndex: Integer): Integer; overload;
function IndexOfAnyUnquoted(const AnyOf: array of Char; StartQuote, EndQuote: Char; StartIndex: Integer; Count: Integer): Integer; overload;

Properties

Type Visibility Source Unit Parent
function public System.SysUtils.pas System.SysUtils TStringHelper

Description

Returns the index of the first occurrence of any of the specified characters outside the specified type of quotes in the specified string, or -1 if there is no matching unquoted character.

IndexOfAnyUnquoted follows these rules:

  • A character is considered to be quoted if it is located after the specified start quote and before the specified end quote.
  • If there is no end quote closing a start quote, any character after that start quote is considered to be quoted.
  • Each end quote closes a previous start quote; a single end quote cannot close multiple start quotes.

IndexOfAnyUnquoted receives the following parameters:

  • AnyOf is an array of characters to match. IndexOfAnyUnquoted looks for the first occurrence of any of these characters outside the specified quotes.
  • StartQuote is the start quote character.
  • EndQuote is the end quote character. It may be the same as the start quote character.
  • StartIndex (optional) is the index of the string where IndexOfAnyUnquoted starts searching for a matching character. You can think of it as the number of characters at the beginning of the string to skip during the search. If you do not specify a start index, IndexOfAnyUnquoted searches from the beginning of the string.
    Warning: Quotes with an index lower than the specified StartIndex are skipped as well, and they are not taken into account to determine which characters are quoted and which characters are unquoted. See the examples with a StartIndex value in the examples table below.
  • Count (optional) is the number of characters of the string to search. If you do not specify a value for Count, IndexOfAnyUnquoted searches until the end of the string.

Examples

The following table shows some examples of executing IndexOfAnyUnquoted with different arguments. The character that determines the returned index, if any, is displayed in bold font in the String column of the table.

String AnyOf StartQuote EndQuote StartIndex Count Result (Index) Notes
"This" is it i " " 7
"This is it i " " -1 There is no end quote, so everything after the start quote is considered quoted.
"This" "is" "it" i " " -1 Only spaces are unquoted.
<This <is>> it i < > 12 Characters within nested quotes are ignored as well.
"This" is it i " " 1 3 IndexOfAnyUnquoted skips the start quote because of the value of StartIndex, so the end quote becomes a start quote.
This" "is" "it i " " 5 -1 IndexOfAnyUnquoted skips the first start quote because of the value of StartIndex, so end quotes become start quotes and vice versa, and the only unquoted characters are now spaces.

See Also