[英]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.