1

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

一些测试句。第二句。

应转换为:

一些测试语句。第二句。

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

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

上述拒绝失败。似乎这部分:UCase("$1")不起作用。我得到的是小写的整个字符串。

4

1 回答 1

2

正如评论中提到的,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?

让我知道这可以帮助你。

于 2015-11-30T15:02:58.397 回答