convert array to tab delimited data
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
convert array to tab delimited data
I am trying to build a function that will take any array (no matter how many dimensions it might have) and display it as tab delimited data. I found this on livecode lessons: (how-do-i-display-an-array-in-human-readable-form) and tried modifying it to this:
function displayArray pArray, pIndent
# create the variable that loops through the keys in the array
local tKey
if pArray is an array then
# print information to indicate that we are entering a new nested level of the array
get return
# create the indentation
put tab after pIndent
repeat for each key tKey in pArray
# call displayArrayData with a nested array
put format("%s%s%s\n", pIndent, tKey, displayArray (pArray[tKey], pIndent)) after it
end repeat
delete the last char of it
put it into tlist
else
put pArray into tlist
end if
return tlist
end displayArray
This gets me close but the array is displayed in kind of an outline form. What I want is tab delimited. Does anyone have any thoughts?
function displayArray pArray, pIndent
# create the variable that loops through the keys in the array
local tKey
if pArray is an array then
# print information to indicate that we are entering a new nested level of the array
get return
# create the indentation
put tab after pIndent
repeat for each key tKey in pArray
# call displayArrayData with a nested array
put format("%s%s%s\n", pIndent, tKey, displayArray (pArray[tKey], pIndent)) after it
end repeat
delete the last char of it
put it into tlist
else
put pArray into tlist
end if
return tlist
end displayArray
This gets me close but the array is displayed in kind of an outline form. What I want is tab delimited. Does anyone have any thoughts?
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: convert array to tab delimited data
Hello inbo,
Do not know if this is the goal but you can very easy show your complete array as a treeview by using the Tree View Widget.
This is very easy .
Place the Tree View widget in a card and give it a name (e.g. myarrayview )
Then use the below statement to fill the tree view widget with your array data.
More info on Tree View Widget
http://livecode.wikia.com/wiki/Tree_view_widget
https://livecode.com/docs/9-0-0/compone ... ew-widget/
Regards,
Paul
Do not know if this is the goal but you can very easy show your complete array as a treeview by using the Tree View Widget.
This is very easy .
Place the Tree View widget in a card and give it a name (e.g. myarrayview )
Then use the below statement to fill the tree view widget with your array data.
Code: Select all
set the arraydata of widget myarrayview to yourarrayname
http://livecode.wikia.com/wiki/Tree_view_widget
https://livecode.com/docs/9-0-0/compone ... ew-widget/
Regards,
Paul
Re: convert array to tab delimited data
Code: Select all
set the itemdel to tab
then create a repeat function to place every item of each line of your data to the field where you want it to be displayed
Re: convert array to tab delimited data
Hi,
Is this what you want?
datas from:
http://lessons.livecode.com/m/4071/l/21 ... dable-form
If yes, then try this script:
and to call this function:
HTH,
Thierry
Is this what you want?
datas from:
http://lessons.livecode.com/m/4071/l/21 ... dable-form
If yes, then try this script:
Code: Select all
function flattenArray A , d1, d2, T, X
if T is empty then
if d1 is empty then put cr into d1
if d2 is empty then put tab into d2
end if
if A is not an array then return T & X & A & d1
repeat for each key K in A
put flattenArray( A[K], d1, d2, T, X & K & d2 ) into T
end repeat
end flattenArray
Code: Select all
on mouseUp
-- use implicit delimiters settings ( d1 and d2)
put flattenArray( tCustomerDataArray) into fld 1
-- or set primaryDelimiter (d1) and use default's secondaryDelimiter
-- put flattenArray( myArray, return )
-- or set both delimiters
-- put flattenArray( myArray, return , " - ")
end mouseUp
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: convert array to tab delimited data
Thierry, wonderful to see you post, it has been much too long!
Re: convert array to tab delimited data
Thierry,
Thank you for the flattenArray function. That was exactly what I needed.
Thank you for the flattenArray function. That was exactly what I needed.
Re: convert array to tab delimited data
Hi inbo712,
welcome to this wonderful forum!
Best
Klaus
Very personal note:
A little e.g. "Hello" would not have hurt for the first posting.
welcome to this wonderful forum!
Best
Klaus
Very personal note:
A little e.g. "Hello" would not have hurt for the first posting.
Re: convert array to tab delimited data
Glad that it works for you!inbo712 wrote: Thank you for the flattenArray function. That was exactly what I needed.
And welcome to the LC world...
Nice to see again your legendary friendly and gentle attitude.bogs wrote: Thierry, wonderful to see you post, it has been much too long!
Much appreciated
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: convert array to tab delimited data
This is VERY useful for callbacks from JavaScript, using LC's javascriptHandlers.
And also (the excellent technique) for use in LC Builder.
Welcome back Thierry, and thanks for that!
And also (the excellent technique) for use in LC Builder.
Welcome back Thierry, and thanks for that!
shiftLock happens
Re: convert array to tab delimited data
Thanks Herman,
If you are using it for this purpose, you might be interested with a more effective one,
hard coding the delimiters:
Code: Select all
function flattenArraySpeedy A, T, X
if A is not an array then return T & X & A & cr
repeat for each key K in A
put flattenArraySpeedy( A[K], T, X & K & tab ) into T
end repeat
end flattenArraySpeedy
viewtopic.php?f=6&t=29798&p=158579&hili ... ne#p158579
Enjoy your day,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!