SSRS 表达式:如何在 table 列中的地址的特殊字符后放置换行符

SSRS expression: How to put a line break after a special character for an address that is in a table column

我在 SSRS 中有一个 table,它有多个地址,它们都很难阅读,我想知道是否可以添加换行符。

所有地址都以 2) 或 3) 或 1) 开头,因此闭括号将是应该出现换行符的标记,删除 ).

当前格式; 5) 乘客电梯 - 保险 - The High St 5-16- 到期 - 22 年 1 月 28 日,5) 乘客电梯 - 保险 - 6 Lovedale Road Flats - 到期 - 21 年 9 月 9 日 5) 乘客电梯 - 保险 - Queens Court 1 - 31 BLOCK- 到期 - 22 年 1 月 14 日

要求格式;

Passenger Lifts - Insurance - The High St 5-16- due - 28 Jan 22,
Passenger Lifts - Insurance - 6 Lovedale Road Flats- due - 09 Sep 21,
Passenger Lifts - Insurance - Queens Court 1 - 31 BLOCK- due - 14 Jan 22

感谢任何提示和技巧

我没有在 VBA 中测试它,但它在 Regex101 中起作用并且通过 Regex Replace 是这样的:

编辑于 2022 年 2 月 4 日:我设法获得了一个 VBA 编辑器,并使内容更加干练和扎实...

Public Sub TestReplaceThroughRegex()
  Dim strOutput As String
  strOutput = _
    ReplaceThroughRegex( _
        "5)Passenger Lifts - Insurance - The High St 5-16- due - 28 Jan 22, 5)Passenger Lifts - Insurance - 6 Lovedale Road Flats- due - 09 Sep 21, 5)Passenger Lifts - Insurance - Queens Court 1 - 31 BLOCK- due - 14 Jan 22" _
        , "\d{1}\)" _
        , "\r" _
    )
    Debug.Print (strOutput)
End Sub

Public Function ReplaceThroughRegex(ByVal strInput As String, ByVal pattern As String, ByVal replacement As String) As String
Static regEx As Object 'VBScript_RegExp_55.RegExp
    'Static declaration means we don't have to create
    'and compile the RegExp object every single time
    'the function is called.

  If strInput = "" Then
    'This is the signal to dispose of oRE
    Set regEx = Nothing
    Exit Function 'with default value
  End If
   
  'Create the RegExp object if necessary
  If regEx Is Nothing Then
    Set regEx = CreateObject("VBScript.Regexp")
  End If
    With regEx
        .Global = True
        .Multiline = True
        .IgnoreCase = False
        .pattern = pattern
    End With
    ReplaceThroughRegex = regEx.Replace(strInput, replacement)
End Function

PS:我假设您在 ) 之前只有一位数字。 如果可能不止一个,请根据您的需要更改为 "\d{1,2}\)""\d{1,3}\)"

如果只有三个可能的值并且您想使用 SSRS 表达式,您可以使用 Replace 函数将“5)”替换为 vbcrlf,这样会插入一个新行。

=REPLACE(Fields!LongString.Value, "5)", vbcrlf)