← instr operator page · string/instr/comp_pattern/manual_ex_2

Manual example 2 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

instr(Me_1, "hello") inside calc, where the new measure Me_2 takes the position.

Manual:

String pattern location, Example 2, output verbatim: "The operator returns the position in the input string of a specified string ( pattern )."

Expected:

Me_2 is 1, 5, 0 and 5; Me_1 is kept.

script.vtl ⇩

DS_r := DS_1[calc Me_2:=instr(Me_1,"hello")];

input/DS_1.csv ⇩

Id_1Id_2Me_1
1Ahello world
2Asay hello
3Ahe
4Ahi, hello!

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

expected/DS_r.csv ⇩

Id_1Id_2Me_1Me_2
1Ahello world1
2Asay hello5
3Ahe0
4Ahi, hello! 5

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": "Integer", "role": "Measure"}
      ]
    }
  ]
}