[英]SSRS expression: How to put a line break after a special character for an address that is in a table column
我在 SSRS 中有一個有多個地址的表,它們都很難閱讀,我想知道是否可以添加換行符。
所有地址都以 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截止日期 - 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
任何提示和技巧表示贊賞
如果只有三個可能的值並且您想使用 SSRS 表達式,則可以使用 Replace function 將“5)”替換為 vbcrlf,這將插入一個新行。
=REPLACE(Fields!LongString.Value, "5)", vbcrlf)
我沒有在 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}\)"
,只要適合您的需要。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.