Is it possible to use one replace function to replace multiple strings in one field?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 17:07:59

问题


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 to 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.


回答1:


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")




回答2:


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.




回答3:


It look nice if you do it with

=Switch(
    Fields!Status.Value = "20", "Entered",
    Fields!Status.Value = "30", "Returned",
    Fields!Status.Value = "200", "Cancelled",
    Fields!Status.Value = "220", "Complete",
    Fields!Status.Value = "300", "Deleted"
)

Got it from another stackoverflow anser



来源:https://stackoverflow.com/questions/7608128/is-it-possible-to-use-one-replace-function-to-replace-multiple-strings-in-one-fi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!