带正则表达式的 SSRS 句子大小写

SSRS sentence case with regex

我想将 SSRS 报告中的字段转换为句子大小写,例如:

some test sentence. second Sentence.

应转换为:

Some test sentence. Second sentence.

我目前正在尝试使用正则表达式:

=System.Text.RegularExpressions.Regex.Replace(
 IIf(IsNothing(Fields!Title.Value), "", LCase(Fields!Title.Value)),
 "(^[a-z])|\.\s+(.)",
 UCase("")
)

上面的 rejex 失败了。似乎部分:UCase("") 不工作。我得到的是小写的整个字符串。

如评论中所述,SSRS 不会将“$1”标识符大写,因为它将其视为文字字符串。

作为解决方法,我建议您使用此自定义代码:

转到报告属性/代码并输入此代码:

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

要使用它,请按如下方式在您的文本框中调用它:

=Code.ProperCase(LCase(Fields!Title.Value))

我测试过这个字符串:

some test sentence. second Sentence. SHOULD THIS BE CAPITALIZED?

它返回:

Some test sentence. Second Sentence. Should this be capitalized?

告诉我这对你有帮助。