Recent

Author Topic: How to split delimited strings?  (Read 7255 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 14223
  • Probably until I exterminate Putin.
Re: How to split delimited strings?
« Reply #15 on: October 14, 2019, 04:10:03 pm »
Jamie's clever use of a variant record yields an elegant and compact solution.
Yes, nice and expressive Pascal. It should also be fast. Compliments, Jamie and Howard.
Specialize a type, not a var.

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: How to split delimited strings?
« Reply #16 on: October 14, 2019, 05:22:07 pm »
Well I guess I learn something, I didn't know you could increment/decrement a Boolean type in fpc.

Thanks for that heads up, I'll use that.  :)

I grow up from the old school of lack of memory and processing speed, I believe in taking the shortcut to most cleanest way to resolve a problem.

 Sometimes it's best to code inline with the basic elements of the language.
The only true wisdom is knowing you know nothing

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to split delimited strings?
« Reply #17 on: October 14, 2019, 06:43:37 pm »
In Pascal Pred(), Succ(), Inc(), Dec() can be used on all ordinal types (except discontinuous enumerations).

Thaddy

  • Hero Member
  • *****
  • Posts: 14223
  • Probably until I exterminate Putin.
Re: How to split delimited strings?
« Reply #18 on: October 14, 2019, 07:12:29 pm »
Like pred(Low()) and Succ(High())...?  :D
Specialize a type, not a var.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to split delimited strings?
« Reply #19 on: October 14, 2019, 07:33:44 pm »
I wrote that Pred and Succ can be used on all ordinal types.
I did not state (or imply) that they can be used on all possible ordinal values.

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: How to split delimited strings?
« Reply #20 on: October 14, 2019, 07:34:31 pm »
In Pascal Pred(), Succ(), Inc(), Dec() can be used on all ordinal types (except discontinuous enumerations).
This is not documented in FPC, but for Delphi compatibility it is also possible to define both Inc and Dec as operators.
Code: Pascal  [Select][+][-]
  1. {$APPTYPE CONSOLE}
  2. {$MODE OBJFPC}
  3. {$MODESWITCH ADVANCEDRECORDS}
  4.  
  5. type
  6.   TSomeRec = record
  7.   strict private
  8.     FStringField: string;
  9.   public
  10.     constructor Create(const AStringField: string);
  11.     class operator Inc(const R: TSomeRec): TSomeRec;
  12.     property SomeField: string read FStringField;
  13.   end;
  14.  
  15. class operator TSomeRec.Inc(const R: TSomeRec): TSomeRec;
  16. begin
  17.   Result.FStringField := R.SomeField + '+1';
  18. end;
  19.  
  20. constructor TSomeRec.Create(const AStringField: string);
  21. begin
  22.   FStringField := AStringField;
  23. end;
  24.  
  25. var
  26.   R: TSomeRec;
  27. begin
  28.   R := TSomeRec.Create('test');
  29.   Inc(R);
  30.   Writeln(R.SomeField); // 'test+1'
  31.   Readln;
  32. end.

Thaddy

  • Hero Member
  • *****
  • Posts: 14223
  • Probably until I exterminate Putin.
Re: How to split delimited strings?
« Reply #21 on: October 14, 2019, 08:16:51 pm »
In that case it *should * be documented. Will you ask Michael to do so? (Great find)
Specialize a type, not a var.

Kays

  • Hero Member
  • *****
  • Posts: 569
  • Whasup!?
    • KaiBurghardt.de
Re: How to split delimited strings?
« Reply #22 on: October 14, 2019, 08:19:33 pm »
This is not documented in FPC, […]
It’s documented since r1595 (confer #0035347).
Yours Sincerely
Kai Burghardt

Thaddy

  • Hero Member
  • *****
  • Posts: 14223
  • Probably until I exterminate Putin.
Re: How to split delimited strings?
« Reply #23 on: October 14, 2019, 09:34:30 pm »
Yea, I forgot, Kays.... I was desperately ill with flue at that point  ;)

(IOW I reported that myself  :-[ )
Specialize a type, not a var.

 

TinyPortal © 2005-2018