Recent

Author Topic: String.Split(const Separators: array of Char; Options: TStringSplitOptions)  (Read 597 times)

Bart

  • Hero Member
  • *****
  • Posts: 4472
    • Bart en Mariska's Webstek
Hi,

I must be missing something obvious.
But given the following definition of the Split() helper function for strings:
Code: [Select]
=pascal]
Function Split(const Separators: array of Char; Options: TStringSplitOptions): TStringArray; overload;

Why does this not compile:
Code: Pascal  [Select][+][-]
  1. var
  2.   SA: TStringArray;  
  3.   ...
  4.   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

howardpc

  • Hero Member
  • *****
  • Posts: 3784
Re: String.Split(const Separators: array of Char; Options: TStringSplitOptions)
« Reply #1 on: September 16, 2021, 08:20:36 pm »
It looks like a bug.
Perhaps the compiler can't sort out the multiplicity of .Split overloads correctly, or perhaps the scoped enum is confusing it?
« Last Edit: September 16, 2021, 08:23:42 pm by howardpc »

Bart

  • Hero Member
  • *****
  • Posts: 4472
    • Bart en Mariska's Webstek
Re: String.Split(const Separators: array of Char; Options: TStringSplitOptions)
« Reply #2 on: September 16, 2021, 10:19:22 pm »
I'll ask on ML as well.

Bart

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1053
Re: String.Split(const Separators: array of Char; Options: TStringSplitOptions)
« Reply #3 on: September 17, 2021, 03:28:03 am »
hello,
[#0..#32] is a set of char not an array of char :
this code can be compiled :
Code: Pascal  [Select][+][-]
  1. var
  2.   S: String;
  3.   SA: TStringArray;
  4. begin
  5.   S := 'coucou c''est moi';
  6.   SA := S.Split([#0,#13,#32],TStringSplitOptions.ExcludeEmpty);
  7.  
  8. end;    

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Bart

  • Hero Member
  • *****
  • Posts: 4472
    • Bart en Mariska's Webstek
Re: String.Split(const Separators: array of Char; Options: TStringSplitOptions)
« Reply #4 on: September 17, 2021, 12:37:58 pm »
[#0..#32] is a set of char not an array of char :

Yes (Michael pointed out the same on the ML).

Code: Pascal  [Select][+][-]
  1. SA := S.Split([#0,#13,#32],TStringSplitOptions.ExcludeEmpty);

At first when I started this, I had [#10,#11,#12,#13] as the first parameter and it failed to compile.
Or at least I thought I had, but your example compiles just fine, so I must have made a typo or something in my code.
Only at a later point in testing I used [#0..#32].

Anyhow: mystery solved.

Bart

PS. An overload with TSysCharSet instead of "Array of Char" would have made more sense to me.

[ETA] I tried to add [Solved] to the subjectline, but the subjectline is too long...[/ETA]
« Last Edit: September 17, 2021, 12:39:46 pm by Bart »

 

TinyPortal © 2005-2018