← replace operator page · string/replace/ds_two/manual_ex_1

Manual example 1 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

replace(DS_1, "ello", "i"): ello replaced by i in every value.

Manual:

String pattern replacement, Example 1, output verbatim: "Replaces all the occurrences of a specified string-pattern (pattern1) with another one (pattern2)."

Expected:

hello world, say hello and hello! give hi world, say hi and hi!; he has no ello and is kept.

script.vtl ⇩

DS_r := replace (DS_1,"ello","i");

input/DS_1.csv ⇩

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

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_1
1Ahi world
2Asay hi
3Ahe
4Ahi!

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