[英]SSRS sentence case with regex
I want to convert a field in a SSRS report to sentence case eg: 我想将SSRS报告中的字段转换为句子大小写,例如:
some test sentence.
一些测试句子。 second Sentence.
第二句。
should be converted to: 应转换为:
Some test sentence.
一些测试句子。 Second sentence.
第二句话。
I am currently attempting this using a regular expression: 我目前正在尝试使用正则表达式:
=System.Text.RegularExpressions.Regex.Replace(
IIf(IsNothing(Fields!Title.Value), "", LCase(Fields!Title.Value)),
"(^[a-z])|\.\s+(.)",
UCase("$1")
)
The above rejex is failing. 上面的拒绝失败。 It seems that the part:
UCase("$1")
is not working. 似乎该部分:
UCase("$1")
无法正常工作。 What I'm getting is the entire string in lowercase. 我得到的是整个字符串都小写。
As mentioned in comments SSRS will not capitalize "$1" identifier since it will take it as literal string. 如注释中所述,SSRS不会将大写的“ $ 1”标识符大写,因为它将其当作文字字符串。
As workaround I suggest you use this custom code: 作为解决方法,我建议您使用以下自定义代码:
Go to Report Properties / Code and put this code: 转到报告属性/代码,然后输入以下代码:
Function ProperCase(InputString as String) As String
Dim i as Integer
If InputString <> "" Then
Mid(InputString , 1, 1) = UCase(Mid(InputString , 1, 1))
For i = 1 To Len(InputString) - 1
If Mid(InputString, i, 2) = "." + " " Then
Mid(InputString, i + 2, 1) = UCase(Mid(InputString, i + 2, 1))
End If
Next
Return InputString
End If
End Function
To use it invoke it in your textbox as follows: 要使用它,请在文本框中按如下所示调用它:
=Code.ProperCase(LCase(Fields!Title.Value))
I've tested this string: 我已经测试了这个字符串:
some test sentence. second Sentence. SHOULD THIS BE CAPITALIZED?
It returned: 它返回:
Some test sentence. Second Sentence. Should this be capitalized?
Let me know it this can help you. 让我知道这可以为您提供帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.