KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Get Text representation of a collection
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: May 10, 2019
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

String command can be used to get string form of the numeric, Date, Time, string or Boolean types. However, it does not yet support new types such as object and collection. Below is a project method get a representation from a collection in string form:

// Name: colToText
// Description: Method returns a string form of collection without surrounding brackets
// Parameters: $1 (Collection) - target collection

C_COLLECTION($1)
C_TEXT($0;$json_t)
$json_t:=JSON Stringify($1)
$json_t:=Delete string($json_t;0;1)
$0:=Delete string($json_t;Length($json_t);1)


This method uses JSON Stringfy command to get collection in string and trims the surrounding square brackets of the string. Below are some examples:

C_COLLECTION($1dCol;$2dCol;$3dCol)
$1dCol:=New collection(1;2;3;4;5;6)
$2dCol:=New collection(1;2;3;New collection(4;5))
$3dCol:=New collection(1;2;3;New collection(4;New collection(5;6)))
$r1:=colToText ($1dCol)  //result: "1,2,3,4,5,6"
$r2:=colToText ($2dCol)  //result: "1,2,3,[4,5]"
$r3:=colToText ($3dCol)  //result: "1,2,3,[4,[5,6]]"