Recent

Author Topic: TStringList CommaText, Values  (Read 212 times)

BubikolRamios

  • Full Member
  • ***
  • Posts: 194
TStringList CommaText, Values
« on: August 14, 2020, 08:30:01 am »
If I would go and input regex containing '='
like:

Quote
MenuItem.CommaText := '^=.*?$=true,....';

would that work:

Code: Pascal  [Select][+][-]
  1. program TStringList_name-value_pairsFTW;
  2.  
  3. uses
  4.   classes;
  5.  
  6. var
  7.   MenuItem : TStringList;
  8.   i : integer;
  9.  
  10. begin
  11.   MenuItem := TStringList.Create;
  12.   MenuItem.CommaText := 'Chicken=5,Beef=7,Cheese=9';
  13.      
  14.   for i := 0 to 2 do
  15.     writeln(MenuItem.Names[i],' : ',MenuItem.Values[MenuItem.Names[i]],' Dollars');
  16.   MenuItem.Free;
  17.  
  18.  
  19.  

Probably not, how to then push 1D array to TstringList ? Or any other idea how to put into memory data pairs like:
Quote
"^=.*?$"."true"
"^sda"."false"
...

Creating and then resizing dynamic 2D array each time adding new item seems ugly.
« Last Edit: August 14, 2020, 08:35:31 am by BubikolRamios »
lazarus-2.0.2-fpc-3.0.4-win32

mangakissa

  • Hero Member
  • *****
  • Posts: 1090
Re: TStringList CommaText, Values
« Reply #1 on: August 14, 2020, 09:24:19 am »
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

TRon

  • Hero Member
  • *****
  • Posts: 536
Re: TStringList CommaText, Values
« Reply #2 on: August 14, 2020, 09:39:08 am »
If I would go and input regex containing '='  like:
...
would that work:
No, that would not work with commatext.

Use property delimitedtext instead, as that is more flexible.

Or, as indicated by mangakissa, use the values property or use default method of Add to create/assign your (custom) name-value pairs.
« Last Edit: August 14, 2020, 10:29:43 am by TRon »

 

TinyPortal © 2005-2018