Sign in Join

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

Mailing lists / fpc-pascal / 2014-01

ExtractStrings skips empty string parts?

8 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

silvioprog

Hello,

Conforms issue #16043:

"ExtractStrings in the Classes unit skips over empty text. For example:

"AAA,BBB,,CCC"

is converted to:

"AAA"
"BBB"
"CCC"

I was expecting:

"AAA"
"BBB"
""
"CCC"

Is this the intended behavior, or is it a bug?".

So, if I try:

procedure TForm1.Button1Click(Sender: TObject);
var
  s: TStringList;
begin
  s := TStringList.Create;
  try
    s.StrictDelimiter := True;
    s.Delimiter := '|';
    ExtractStrings(['|'], [], 'A|B||C', s);
    ShowMessage(IntToStr(s.Count));
  finally
    s.Free;
  end;
end;

It returns 3. But, if I try:

procedure TForm1.Button2Click(Sender: TObject);
var
  s: TStringList;
begin
  s := TStringList.Create;
  try
    s.StrictDelimiter := True;
    s.Delimiter := '|';
    s.DelimitedText := 'A|B||C';
    ShowMessage(IntToStr(s.Count));
  finally
    s.Free;
  end;
end;

It returns 4.

How to configure ExtractStrings to works without skip empty strings like DelimitedText?

Thank you!

Silvio Clécio My public projects - github.com/silvioprog

Reply by email

Michael Van Canneyt
to silvioprog
silvioprog wrote 5 lines
Hello, Conforms issue #16043: "ExtractStrings in the Classes unit skips over empty text. For example:

Yes. This is delphi compatible.

The only possibility is to add a new argument ExtractEmpty : Boolean = False;
which would, when set to true, also extract empty values.

Michael.

Reply by email

Frederic Da Vitoria
to Michael Van Canneyt

2014/1/26 Michael Van Canneyt

Show quoted text 12 lines
On Sun, 26 Jan 2014, silvioprog wrote: Hello, > > Conforms issue #16043: > > "ExtractStrings in the Classes unit skips over empty text. For example: > Yes. This is delphi compatible.

I can imagine that the Delphi developers started from a routine to extract words from texts, where several spaces between 2 words would count only as one separator.

Frederic Da Vitoria (davitof) Membre de l'April - « promouvoir et défendre le logiciel libre » - http://www.april.org

Reply by email

silvioprog
to Michael Van Canneyt: Yes. This is delphi compatible. The only possibility is to add a new argument…

2014-01-26 Michael Van Canneyt

Show quoted text 17 lines
On Sun, 26 Jan 2014, silvioprog wrote: > Hello, > > Conforms issue #16043: > > "ExtractStrings in the Classes unit skips over empty text. For example: > Yes. This is delphi compatible. The only possibility is to add a new argument ExtractEmpty : Boolean = False; which would, when set to true, also extract empty values. Michael.

It would be a nice idea an new argument or an overloaded function. Could use the StrictDelimiter name, to maintain compatibility with the already used name in TStrings. :)

Silvio Clécio My public projects - github.com/silvioprog

Reply by email

Michael Van Canneyt
to silvioprog
silvioprog wrote 19 lines
2014-01-26 Michael Van Canneyt On Sun, 26 Jan 2014, silvioprog wrote: Hello, Conforms issue #16043: "ExtractStrings in the Classes unit skips over empty text. For example: Yes. This is delphi compatible. The only possibility is to add a new argument ExtractEmpty : Boolean = False; which would, when set to true, also extract empty values. Michael. It would be a nice idea an new argument or an overloaded function. Could use the StrictDelimiter name, to maintain compatibility with the already used name in TStrings. :)

Sure. Feel free to supply a patch.

Michael.

Reply by email

silvioprog
to Michael Van Canneyt

2014-01-27 Michael Van Canneyt

Show quoted text 31 lines
On Mon, 27 Jan 2014, silvioprog wrote: > 2014-01-26 Michael Van Canneyt > On Sun, 26 Jan 2014, silvioprog wrote: > Hello, > > Conforms issue #16043: > > "ExtractStrings in the Classes unit skips over empty text. > For example: > > > Yes. This is delphi compatible. > > The only possibility is to add a new argument ExtractEmpty : Boolean = > False; > which would, when set to true, also extract empty values. > > Michael. > > > It would be a nice idea an new argument or an overloaded function. Could > use the StrictDelimiter name, to maintain > compatibility with the already used name in TStrings. :) > Sure. Feel free to supply a patch. Michael.

Done: http://bugs.freepascal.org/view.php?id=25633.

Thank you again! (y)

Silvio Clécio My public projects - github.com/silvioprog

Reply by email

Michael Van Canneyt
to silvioprog
silvioprog wrote 29 lines
2014-01-27 Michael Van Canneyt On Mon, 27 Jan 2014, silvioprog wrote: 2014-01-26 Michael Van Canneyt       On Sun, 26 Jan 2014, silvioprog wrote:             Hello,             Conforms issue #16043:             "ExtractStrings in the Classes unit skips over empty text. For example: Yes. This is delphi compatible. The only possibility is to add a new argument ExtractEmpty : Boolean = False; which would, when set to true, also extract empty values. Michael. It would be a nice idea an new argument or an overloaded function. Could use the StrictDelimiter name, to maintain compatibility with the already used name in TStrings. :) Sure. Feel free to supply a patch. Michael. Done: http://bugs.freepascal.org/view.php?id=25633.

Solved, but I did it with a new argument. Try to avoid code duplication...

Michael.

Reply by email

silvioprog
to Michael Van Canneyt

2014-01-28 Michael Van Canneyt

Show quoted text 40 lines
On Mon, 27 Jan 2014, silvioprog wrote: > 2014-01-27 Michael Van Canneyt > On Mon, 27 Jan 2014, silvioprog wrote: > 2014-01-26 Michael Van Canneyt > On Sun, 26 Jan 2014, silvioprog wrote: > Hello, > > Conforms issue #16043: > > "ExtractStrings in the Classes unit skips over > empty text. For example: > > > Yes. This is delphi compatible. > > The only possibility is to add a new argument ExtractEmpty : > Boolean = False; > which would, when set to true, also extract empty values. > > Michael. > > > It would be a nice idea an new argument or an overloaded > function. Could use the > StrictDelimiter name, to maintain > compatibility with the already used name in TStrings. :) > > > Sure. Feel free to supply a patch. > Michael. > > > Done: http://bugs.freepascal.org/view.php?id=25633. > Solved, but I did it with a new argument. Try to avoid code duplication... Michael.

Tested and worked perfectly. Nice job! :)

Silvio Clécio My public projects - github.com/silvioprog

Reply by email