Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2021-09

String.Split(const Separators: array of Char; Options: TStringSplitOptions)

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bart

Hi,

I must be missing something obvious.
But given the following definition of the Split() helper function for strings:

Function Split(const Separators: array of Char; Options:
TStringSplitOptions): TStringArray; overload; (fpc 3.2.2)

Why does this not compile:

var
  SA: TStringArray;
  ...
  SA := S.Split([#0..#32],TStringSplitOptions.ExcludeEmpty);
test.pas(236,59) Error: Incompatible type for arg no. 2: Got
"TStringSplitOptions", expected "Char".

I feel I must be blind...

Bart
Michael Van Canneyt
to Bart
Bart wrote 14 lines
Hi, I must be missing something obvious. But given the following definition of the Split() helper function for strings: Function Split(const Separators: array of Char; Options: TStringSplitOptions): TStringArray; overload; (fpc 3.2.2) Why does this not compile: var SA: TStringArray; ... SA := S.Split([#0..#32],TStringSplitOptions.ExcludeEmpty);

You are passing not an array of char but a set of char.

This works:

SA := S.Split(#0#32,TStringSplitOptions.ExcludeEmpty);

An array of char is a string.

But the message is indeed confusing. My guess is that the compiler decided
it was this overload;
function TStringHelper.Split( const Separators: array of Char;
   AQuote: Char
):TStringArray; overload;

Michael.

Ondrej Pokorny
to Michael Van Canneyt
Michael Van Canneyt wrote 18 lines
On Thu, 16 Sep 2021, Bart via fpc-pascal wrote: > Hi, > > I must be missing something obvious. > But given the following definition of the Split() helper function for > strings: > > Function Split(const Separators: array of Char; Options: > TStringSplitOptions): TStringArray; overload; (fpc 3.2.2) > > Why does this not compile: > > var >  SA: TStringArray; >  ... >  SA := S.Split([#0..#32],TStringSplitOptions.ExcludeEmpty); You are passing not an array of char but a set of char.

Yes, I just add that a set of char would be handier but it cannot be used since Unicode Delphi because Char=UnicodeChar.

Ondrej