6

In my report I need to use the built-in replace function to replace for example "a" with "b" and "c" with "d".

When I just use 2 functions like this: Replace(Fields!field1.Value, "a", "b") & Replace(Fields!field1.Value, "c", "d") I get the text from the field twice in my report.

Is it possible to do this? Maybe nest two replace functions? I'm new to reporting services so I could be missing a very obvious solution to this.

Note: I would write my own code to do this but the report is for Microsofts Dynamics CRM 2011 which doesn't allow custom code in a report.

2 Answers 2

17

You have to nest the function's

For example to replace 1 with a and 0 with b you can write the expression below

=Replace(Replace(Fields!field1.Value,"1","a"),"0","b")

1
  • Maybe you could use the built-in System.Text.RegularExpressions.Regex.Replace function, but I am not too familiar with regular expressions
    – niktrs
    Sep 30, 2011 at 11:08
0

This can be a bit tricky (at first) when you have a string that has part of it repeated in the string after it that you also want to replace. To give you an example: If you use the nested function from niktrs to replace "Test" with "Test A" and "Test B" with "Test C" it returns "Test A" and "Test A B". In this example you need to adjust the expression to:

=Replace(Replace(Fields!Field1.Value,"Test","Test A"),"Test A B","Test C")

With 2 or more of these type of strings you need to work your way (down the tablix) to the last value that needs replacing, which could leave you with a relatively lengthy expression, unfortunately. It's probably better to alter the query for the dataset you're working with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.