Recent

Author Topic: [CLOSED] characters disapear splitting a string representing an array  (Read 3608 times)

ratmalwer

  • Jr. Member
  • **
  • Posts: 57
In a Database I have a string witch obviously represents an array.

Code: Pascal  [Select][+][-]
  1. Tier||0,Tier|Insekte||1,Tier|Insekte|Biene||2,Pflanze||3,Pflanze|Blume||4,Pflanze|Blume|Zinnie||5

When I loop through the string to split the Words, I realize that the following characters disapear.

Code: Pascal  [Select][+][-]
  1. ||0   ||1   ||2  ||3   ||4   ||5

Here an example how I  do that and gives the correct result.
Code: Pascal  [Select][+][-]
  1.     ende := Length(str);
  2.     for i := ende downto 1 do begin
  3.         if str[i] = ',' then begin
  4.            out := out + '<' + copy(str,i+1,ende -i);
  5.            ende := i-1;
  6.         end;
  7.         if i = 1 then begin
  8.            out := out + '<' + copy(str,0,ende);
  9.         end;
  10.     end;
  11.     showmessage('out: ' + out);  
  12.  

So I think there is a hidden arrayfunction.

Before I go on I want to assure whats going on. Maybe I cold take further advantage going on with this project.
Is there a documentation of that availabe?

Postscriptum:
I just found that the removal must take place earliey by moving the value to my str....
« Last Edit: November 27, 2021, 08:26:26 pm by ratmalwer »

Bart

  • Hero Member
  • *****
  • Posts: 4689
    • Bart en Mariska's Webstek
Re: characters disapear splitting a string representing an array
« Reply #1 on: November 27, 2021, 05:59:52 pm »
Exactly how do you want the output to be, given the inputstring in the example?

Bart

ratmalwer

  • Jr. Member
  • **
  • Posts: 57
Re: characters disapear splitting a string representing an array
« Reply #2 on: November 27, 2021, 06:06:06 pm »
Hi Bart

just realiyzed the effect happens on the way from DB to my string.
actually I wanted to delete this question until I foud out more myself, but it  cannot be deleted.  :o

Bart

  • Hero Member
  • *****
  • Posts: 4689
    • Bart en Mariska's Webstek
Re: characters disapear splitting a string representing an array
« Reply #3 on: November 27, 2021, 06:12:39 pm »
You can lock the topic IIRC.
Or you can edit your first post and edit the subjectline to something like "[CLOSED] characters disapear splitting a string representing an array"

Bart

wp

  • Hero Member
  • *****
  • Posts: 9592
Re: characters disapear splitting a string representing an array
« Reply #4 on: November 27, 2021, 06:13:28 pm »
In a Database I have a string witch obviously represents an array.

Code: Pascal  [Select][+][-]
  1. Tier||0,Tier|Insekte||1,Tier|Insekte|Biene||2,Pflanze||3,Pflanze|Blume||4,Pflanze|Blume|Zinnie||5
I don't think that this is a simple array, it looks more like a tree
Code: [Select]
Tier
  Insekte
    Biene
Pflanze
  Blume
    Zinnie

The syntax for each tree element ("node") is
  <node1>|<node2>|...|<last node>||<index of last nade>

The comma separates these paths. The single '|' separates the nodes. Double '||' is the end of a branch of nodes. The number is the index of the end node.

You can use a TTreeView to display this hierarchical information in a tree.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

ratmalwer

  • Jr. Member
  • **
  • Posts: 57
Re: characters disapear splitting a string representing an array
« Reply #5 on: November 27, 2021, 08:21:09 pm »
Finally I found the ghost who removed the ||   !
I was it myself in a other function and reused the same Variable  >:(

Thanks WP for the hint with the node - lets see if it makes my life easyer.

 

TinyPortal © 2005-2018