View Issue Details

IDProjectCategoryView StatusLast Update
0035663FPCCompilerpublic2019-06-03 08:36
ReporterAlly Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
PlatformPCOSWindows 
Product Version3.0.4 
Summary0035663: For a string that ends with the delimiter, split returns one string too little.
DescriptionIn my opinion Split should return three strings for a string with two delimiters, even if the last one is an empty string.
Steps To ReproduceThe following example is a nice way to try it out.

    procedure TForm1.Button1Click(Sender: TObject);
    var
      Zeile: String;
      Spalte: TStringArray;
    begin
      //Zeile := 'F0;F1;F2'; // High(Spalte) = 2 = Ok
      //Zeile := ';F1;F2'; // High(Spalte) = 2 = Ok
      //Zeile := ';;F2'; // High(Spalte) = 2 = Ok
      //Zeile := 'F0;;F2'; // High(Spalte) = 2 = Ok

      //Zeile := ';;'; // High(Spalte) = 1 = Falsch
      //Zeile := 'F0;F1;'; // High(Spalte) = 1 = Falsch
      //Zeile := 'F0;;'; // High(Spalte) = 1 = Falsch
      Zeile := ';F1;'; // High(Spalte) = 1 = Falsch

      Spalte := Zeile.Split(';');

      LabelSpaltenIndex.Caption := IntToStr(High(Spalte));

      Label_Index_0.Caption := Spalte[0];
      Label_Index_1.Caption := Spalte[1];
      Label_Index_2.Caption := Spalte[2];
    end;
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Relationships

duplicate of 0035669 resolvedMichael Van Canneyt For a string that ends with the delimiter, split returns one string too little. 

Activities

Michael Van Canneyt

2019-06-02 11:39

administrator   ~0116528

I re-checked, the current behaviour is Delphi compatible.
But I agree it is not logical behaviour.

I have added a line to the documentation to make this clear.

Michael Van Canneyt

2019-06-03 08:36

administrator   ~0116545

Update:

It seems the behaviour became more logical in Delphi Rio, so I adapted the implementation to match Delphi Rio.
(see related bugreport)

It should now behave as you (and I :) ) expect !

Issue History

Date Modified Username Field Change
2019-06-01 18:32 Ally New Issue
2019-06-01 18:39 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-06-01 18:39 Michael Van Canneyt Status new => assigned
2019-06-02 11:39 Michael Van Canneyt Status assigned => resolved
2019-06-02 11:39 Michael Van Canneyt Resolution open => no change required
2019-06-02 11:39 Michael Van Canneyt FPCTarget => -
2019-06-02 11:39 Michael Van Canneyt Note Added: 0116528
2019-06-02 18:54 Michael Van Canneyt Relationship added duplicate of 0035669
2019-06-03 08:36 Michael Van Canneyt Note Added: 0116545