← substr operator page · string/substr/comp_start_len/manual_ex_3

Manual example 3 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

substr(Me_2, 1, 5) inside calc, where the result replaces the measure Me_2.

Manual:

Sub-string extraction, Example 3, 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_2 is mediu, short and "this " (with its trailing space); Me_1 is unchanged.

script.vtl ⇩

DS_r:= DS_1 [ calc Me_2:= substr ( Me_2 , 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
1Ahello worldmediu
1Babcdefghilmnoshort
2Apqrstuvwxyzthis

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"}
      ]
    }
  ]
}