> For the complete documentation index, see [llms.txt](https://docs.cloudfabrix.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cloudfabrix.io/rda/rda-userguide/rda-aiops-studio/examples-jupyter/data-mapping-cfxdm-dm-functions/replace-function.md).

# Replace

### Replace

Replaces old value with new value in the input string @param old value, Type string. @param new value, Type string. Input must be a string.

Replace 'oldvalue' with 'newvalue' in the input string\
&#x20;                   @param oldvalue Type string \
&#x20;                   @param newvalue Type string\
&#x20;                    Input must be a string

This function allows users to replace or substitute a new string value in place of an old existing string value. This allows users to modify column values and add additional string values as per need and requirement&#x20;

### Example 1:&#x20;

Step 1: Create an empty **replace\_example** using AIOps studio as shown in the below screenshot.

![Empty pipeline 'replace\_example' created in RDA ](/files/-MbolO4TLBx0DFL_7lnj)

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.\
\
\&#xNAN;*`##### This pipeline creates a simple record for an attribute (column)`* \
*`##### using AIOps studio.`*\
\
*`##### RDA function replace is used to demo this example.`*\
*`##### This function uses 'newvalue' to replace 'oldvalue' both are in`* \
*`##### string format.`*\
*`##### Function 'replace' replaces old value with new value`*\
\
*`@dm:empty`* \
*`--> @dm:addrow id = '1' & category = 'Cluster-1' & value = 10`*\
*`--> @dm:addrow id = '2' & category = 'Cluster-2' & value = 101`*\
*`--> @dm:addrow id = '3' & category = 'Cluster-3' & value = 21`*\
*`--> @dm:addrow id = '4' & category = 'Cluster-4' & value = 30`*\
*`--> @dm:addrow id = '5' & category = 'Test-Cluster-5' & value = 500`*\
*`--> @dm:addrow id = '6' & category = 'Cluster-6' & value = 50`*\
*`--> @dm:map func = 'replace' & oldvalue = 'Cluster' & newvalue = 'CFX-Cluster' & attr = 'category'`*&#x20;

!['replace' pipeline code added](/files/-MiQKHCDCnA-T1bsicrf)

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

![RDA verifies the replace pipeline code snippet](/files/-MiQL-DVaDlsRWJOY7lG)

Step 4:  Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

![RDA executes 'replace pipeline'  code snippet without any errors](/files/-MiQLJSNx9lOr0Ryd9RC)

Step 5: RDA uses the replace function to replace the old value with a new value for the selected column. Click on Verify to check replaced values as shown below.

![Replaced Values](/files/-MiQLv3C2PbzP4aWU8Yj)

Simple Example - The following is a simple example of another example and final verify output where attribute 'column1' has a value of "Hello abc World" is replaced with "Hello CFX World" after successful execution of pipeline. Try this on your own (as shown below screenshot).

![](/files/-Mboq_aiR8BzGZ8xYd0j)

### Example 2:&#x20;

This example provides a pipeline that uses the 'replace' function to replace a specific character within a string. This will be useful in case if a user wants to search and replace a special character or add additional tokens etc.

Step 1: Create an empty **replace\_char\_example** using AIOps studio as shown in the below screenshot.

![Empty 'replace\_char\_example' pipeline.](/files/-Mbs3vq16f8wDgliRcBG)

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.\
\
\&#xNAN;*`##### This pipeline creates a simple record for an attribute (column)`* \
*`##### using AIOps studio.`*\
\
*`##### RDA function replace is used to demo this example.`*\
*`##### This function uses 'newvalue' to replace 'oldvalue' both are in`* \
*`##### string format.`*\
*`##### Function 'replace' replaces char '"' with empty char ''`*\
\
*`@dm:empty`* \
*`--> @dm:addrow column = 'Hello " World'`*\
*`--> @dm:eval column = "column.replace(chr(34),'')"`*

*Note: Users can use this example to try other characters replacements and/or other character token replacements*

![](/files/-Mbs8wTX5PAuwwyKafsu)

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

![RDA verifies validation of pipeline syntax.](/files/-Mbs9JIloq4T6bmracBZ)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

![Successful execution of above pipeline without any errors.](/files/-Mbs9lsGJslJa3iLL_mM)

Step 5: RDA uses the replace function to replace a character from the string with an empty token and prints the output of the original string as shown in the below screenshot.

Old value --> **'Hello " World'**\
New value --> **'Hello World'**

![RDA uses replace function to replace a char in the string and replaces with empty token (space).](/files/-MbsBd7RuHZxbDUmvmlH)

### Example 3:&#x20;

This example provides a pipeline that uses the 'replace'  function multiple times to search for a pattern that is repeated within a string and replace a common character separator or token within that string.

Step 1: Create an empty **replace\_multi\_char\_example** using AIOps studio as shown in the below screenshot.

![](/files/-MbsFMgfhdY4UT4W2Tqc)

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.\
\
\&#xNAN;*`##### This pipeline creates a simple record for an attribute (mac)`* \
*`##### using AIOps studio.`*\
\
*`##### RDA function replace is used twice to demo this example.`*\
*`##### This function uses 'newvalue' to replace 'oldvalue' both are in`* \
*`##### char format.`*\
*`##### Function 'replace' replaces char '| ' and '|' with ',' character`*  \
\
*`@dm:empty`* \
*`--> @dm:addrow mac = '001b 6384 45e6| 001c 4432 4467  000a 959d 6816|000a 959d 6816'`*  \
*`--> @dm:eval mac = "mac.replace('| ',',').replace('|',',')"`*

*Note: Example uses two patterns to replace special character or token with other tokens within the mac addresses*

![](/files/-MbsMPUXhA59iC_ryPbn)

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

![RDA verifies the pipeline code snippet for any errors](/files/-MbsMxLx8xooDfASxMd_)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

![](/files/-MbsNQv8brQjINkgny95)

Step 5: RDA uses the function 'replace' to replace multi-pattern character tokens, adds 'comma' as token, and returns the string after replacement as shown in the below screenshot.

![RDA 'replace' function replaces special pattern strings for replacement/substitution](/files/-MbsODvdPhCnTs7T805n)

In addition to the above-provided examples, users can use replace for any substitution of strings, special chars, within the pipeline context and store the data.

### Example 4:

This example provides a pipeline that uses the 'replace'  function when the column values have ’Cluster” as the name should add a prefix (e.g. Sub or other prefixes ). This will help users to replace or substitute a string value with custom strings or prefixes.

Step 1: Create an empty **replace\_prefix\_example** using AIOps studio as shown in the below screenshot.

![Empty pipeline  ](/files/-MdxQldhhes7eR0gkZcV)

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.\
\
\&#xNAN;*`##### This pipeline creates set of records that contains Cluster-x as value strings`*\
*`##### in the dataset.`*\
\
*`##### RDA function replace is used to demo this example.`*\
*`##### This function uses replace (substitute) column values that contain Cluster`* \
*`#####  with a prefix 'Sub' and adds it back`*\
*`##### Function 'replace' replaces old value (Cluster) with new value (Sub)`*\
\
*`@dm:empty`* \
*`--> @dm:addrow id = '1' & category = 'Cluster-1' & value = 10`*\
*`--> @dm:addrow id = '2' & category = 'Cluster-2' & value = 101`*\
*`--> @dm:addrow id = '3' & category = 'Cluster-3' & value = 21`*\
*`--> @dm:addrow id = '4' & category = 'Cluster-4' & value = 30`*\
*`--> @dm:addrow id = '5' & category = 'Test-Cluster-5' & value = 500`*\
*`--> @dm:addrow id = '6' & category = 'Cluster-6' & value = 50`*\
*`--> @dm:map func = 'replace' & oldvalue = 'Cluster' & newvalue = 'CFX-Cluster' & attr = 'category'`*

![Pipeline code added to empty pipeline window ](/files/-MdxU02Fwkb_2BpuFO8Z)

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

![Verify the pipeline code by selecting 'Verify' button as shown above](/files/-MdxUeNKdCe927dAIqw2)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

![](/files/-MdxVIC23rH6C2G3oA2w)

Step 5: RDA uses the function 'replace' to replace/substitute the 'Cluster' string with 'CFX' and returns the string after replacement as shown in the below screenshot.

![Successful execution of pipeline and replacement of the 'Cluster' string with 'CFX' prefix.](/files/-MdxW1UafTL3G6C2BuFJ)
