1

I want to convert a field in a SSRS report to sentence case eg:

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. What I'm getting is the entire string in lowercase.

Carel
  • 2,063
  • 8
  • 39
  • 65
  • In SSRS, it seems ("$1") in both uppercase and lowercase are displayed in same way. So the UCase("$1") will not work. – Black_T Nov 30 '15 at 13:39
  • 1
    Try replacing `"(^[a-z])|\.\s+(.)", UCase("$1")` with `"(\w)([^.?!]+[.?!]\s*)", m => UCase(m.Groups[1].Value) + LCase(m.Groups[2].Value)` - or something like that. – Wiktor Stribiżew Nov 30 '15 at 14:51
  • @stribizhev - I'm getting an error [BC30451] that states 'm' is not declared – Carel Nov 30 '15 at 14:58

1 Answers1

2

As mentioned in comments SSRS will not capitalize "$1" identifier since it will take it as literal string.

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.

alejandro zuleta
  • 13,962
  • 3
  • 28
  • 48