For a string that ends with the delimiter, split returns one string too little.
Original Reporter info from Mantis: Ally @sesvena
-
Reporter name:
Original Reporter info from Mantis: Ally @sesvena
- Reporter name:
Description:
In my opinion Split should return three strings for a string with two delimiters, even if the last one is an empty string.
Steps to reproduce:
The 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;
Mantis conversion info:
- Mantis ID: 35663
- OS: Windows
- OS Build: 10
- Platform: PC
- Version: 3.0.4