
Normalizing case in a string - eg. WHAT THIS IS. WHAT -> What this is. What
Jeff is certainly right (there is no built-in function). But if needed,
you can do it without a loop using Instr calls. This is how
I did it (tested code, but not with all possibilities, I'm sure).
Be aware that the beginning of a sentence is recognized:
1. At the very beginning of the string. 2. After a dot + a blank.
However, it should be easy to allow for other sentence
starters, such as ?+blank, !+blank etc. with little extra effort.
Private Function SentenceCase(s As String) As String
Dim ss As String
ss = Replace$(s, ". ", Chr$(0))
ss = Replace$(ss, " ", Chr$(1))
ss = Replace$(ss, Chr$(0), ". ")
ss = StrConv(ss, vbProperCase)
SentenceCase = Replace$(ss, Chr$(1), " ")
End Function
This of course assumes that your original string does not include
Chr$(0) or Chr$(1) which is usually true for text strings.
Although maybe easy to understand, I do not think this code
is anywhere close to optimal performance. I posted it only
because I felt like having a try on this one <g>
Note that you can convert above function to a one-liner
or 'Rickish' function (<g> Sorry, Rick, no insult intended),
similar to
x = Replace$(StrConv(Replace$(Replace$(Replace$(...
HTH, Nikolaus
Quote:
> > This may be what you're after...
> > MyString = StrConv(MyString, vbProperCase)
> No, it's not. He only wants the first letter of a SENTENCE capitalized.
> StrConv() will capitalize the first letter of each WORD.
> There is no built-in function to do this.