← substr operator page · string/substr/ds_start_len/manual_ex_2

Manual example 2 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

substr(DS_1, 1, 5): the first five characters of every value of both measures.

Manual:

Sub-string extraction, Example 2, output verbatim: "The substring starts from the startth character of the input string and has a number of characters equal to the length parameter."

Expected:

Me_1 is hello, abcde and pqrst; Me_2 is mediu, short and "this " (with its trailing space).

script.vtl ⇩

DS_r:= substr ( DS_1 , 1 , 5 );

input/DS_1.csv ⇩

Id_1Id_2Me_1Me_2
1Ahello worldmedium size text
1Babcdefghilmnoshort text
2Apqrstuvwxyzthis is a long description

input/DS_1.json ⇩

{
  "datasets": [
    {
      "name": "DS_1",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
        {"name": "Id_2", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Me_1", "type": "String", "role": "Measure", "nullable": true},
        {"name": "Me_2", "type": "String", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Id_2Me_1Me_2
1Ahellomediu
1Babcdeshort
2Apqrstthis

expected/DS_r.json ⇩

{
  "datasets": [
    {
      "name": "DS_r",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier"},
        {"name": "Id_2", "type": "String", "role": "Identifier"},
        {"name": "Me_1", "type": "String", "role": "Measure"},
        {"name": "Me_2", "type": "String", "role": "Measure"}
      ]
    }
  ]
}