cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to replace multiple strings in the same Expression/field using replaceString function

Kaladhar
Frequent Guest

Hi Team,

I have this requirement to replace multiple strings in an expression which is having two different substrings. 

 

For the Example below:

Category field has two results either A or B and I want to replace 'A' with 'XML' and 'B' with 'TEXT'.

I have used below command with replaceString and it worked for 'A'. 

fieldsAdd replaceString(Category, "A", "XML")

How do I replace the another string B in the same Category field(without adding new fieldsAdd command.)

 

Thanks,

3 REPLIES 3

krzysztof_hoja
Dynatrace Champion
Dynatrace Champion

if "Category field has two results either A or B" why do you need replaceString, not just if?

If my understanding of assumption is correct, this could look like this:

data record(Category="A"),
record(Category="B")
| fieldsAdd Category = coalesce(
  if(Category=="A","XML"),
  if(Category=="B","TEXT"))

krzysztof_hoja_0-1747168120207.png

 

 

This works too. Thank you for the response. 

I was looking to get my hands on 'string functions' by dynatrace also more results might be added in the future.

MuhammadGamal
Helper

Can you try this :
| fieldsAdd CategoryReplaced = replaceString(replaceString(Category, "A", "XML"), "B", "TEXT")
please check the simple Example :

MuhammadGamal_0-1747170555778.png
MuhammadGamal_1-1747170649215.png

 



Featured Posts