cancel
Showing results for 
Search instead for 
Did you mean: 

Replacing multiple strings by the same value

former_member318041
Participant
0 Kudos
1,034

Hi all,
I am working with "SAP BusinessObjects Business Intelligence 4.2" and have the following problem. I need to replace certain strings within a variable by another string.
E.g. if the strings is "abc", "odo" or "xyz", it needs to be replaced by ths string "TEST".

If the content of my variable is "ddddddabcddddd", it should result in "ddddddTESTddddd".
If the content of my variable is "ddddddododdddd", it should also result in "ddddddTESTddddd".
If the content of my variable is "ddddddxyzddddd", it should also result in "ddddddTESTddddd".
...
It is easy to do this, if there is just one string to be replaced, but in my case there are about 15 strings that need to be replaced in the described way.

Any ideas?

Accepted Solutions (1)

Accepted Solutions (1)

ayman_salem
Active Contributor
0 Kudos

Define the following variable:

M_R: =If (Match([your dim]; ("*abc*"))) Then Replace([your dim]; "abc"; "TEST") Else if (Match([your dim]; ("*odo*"))) Then Replace([your dim]; "odo"; "TEST") Else if (Match([your dim]; ("*xyz*"))) Then Replace([your dim]; "xyz"; "TEST") Else [your dim]

...

Then use it in your table

....

hopefully that helps

former_member318041
Participant
0 Kudos

Thank you!

It is not as easy as I expected it to be - thanks again and have a great remaining day!

Henning

Answers (1)

Answers (1)

former_member199945
Active Contributor
0 Kudos

Hi,

Create another variable using inlist operator..

v1= if([string]inlist("abc";"odo";"xyz")) then "test" elseif([string] inlist("def";"ghi") )then "test1" else [string]

Thanks

former_member318041
Participant
0 Kudos

Hi,

thank you for the quick answer, but this is not exactly what I need ...

I want to replace a string within another string and not the complete string!
"ddddddabcddddd" --> "ddddddTESTddddd"

This solution works when you need to replace complete strings, but not parts of a string.
Any ideas?

BR,
Henning

former_member199945
Active Contributor
0 Kudos

Hi,

An answer was provided by Ayman Salem by defining variable using match and replace functions . Try the same formula.

Thanks