SRSS Expression to split strings excluding specific string

岁酱吖の 提交于 2019-12-12 03:23:25

问题


I have the following function (answered by someone on this forum in another question):

Public Function mySplit(ByVal my_field As String) As String
    Dim result As String = ""       
    If my_field is Nothing or my_field = "" Then
        Return result
    End If
    Dim TestArray() As String = my_field.Split(New Char() {" "c})
    Dim word as String
    Dim counter as Integer = 0      
    For Each word In TestArray
        counter = counter +1
        If counter = TestArray.Length Then
            result = result + word
        Else
                result = result + word + vbCrLf 
        End if
    Next
    Return result

End Function

This works to take a collection of words:

"IMAGE01 IMAGE02 IMAGE03" and display them in a report as:

IMAGE01
IMAGE02
IMAGE03

However, I have some images named "IMAGESYS RES01" which because of the above function are being split onto two lines:

IMAGESYS
RES01

I need to avoid this, as the above "IMAGESYS RES01" is just one file.


回答1:


If it always follows the pattern IMAGESYS RESXX this expression should work:

=REPLACE(Code.mySplit(REPLACE(Fields!YourField.Value,"S R","S_R")),"_"," ")

With this example IMAGE01 IMAGE02 IMAGE03 IMAGESYS RES01 IMAGESYS RES02 it should return:

IMAGE01
IMAGE02
IMAGE03
IMAGESYS RES01
IMAGESYS RES02

UPDATE Explanation about how it is working:

The split does nothing different, the change is in the way we pass the values to the mySplit function. The REPLACE(Fields!YourField.Value,"S R","S_R") turns your field in this and pass it to the mySplit function:

IMAGE01 IMAGE02 IMAGE03 IMAGESYS_RES01 IMAGESYS_RES02

The mySplit function will return the below string based on the above passed argument.

IMAGE01
IMAGE02
IMAGE03
IMAGESYS_RES01
IMAGESYS_RES02

Once the function returns the above string the outer REPLACE function replace the _ for " " (whitespace), leaving the string as:

IMAGE01
IMAGE02
IMAGE03
IMAGESYS RES01
IMAGESYS RES02

Let me know if this helps.



来源:https://stackoverflow.com/questions/35181186/srss-expression-to-split-strings-excluding-specific-string

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