Capitalize

This function capitalizes first letter of each of the words in a sentence, basically, 1st letter of anything after space, _, -, . or number

CodeFunctionName
What is this?

Public

Tested

Imported
Function Capitalize(Str)
' This function capitalizes each of the words in a sentence.
Dim t
t = Str
If t < > "" Then
t = UCase(Mid(t, 1, 1)) & Right(t, Len(t) - 1)
For i = 1 To Len(t) - 1
If Mid(t, i, 2) = Chr(13) + Chr(10) Then
' Capitalize words preceded by carriage return plus linefeed combination.
t = Mid(t, 1, i) & UCase(Mid(t, i + 2, 1)) & Mid(t, i+3, Len(t))
End If
If Mid(t, i, 1) = " " or Mid(t, i, 1) = "." or Mid(t, i, 1) = "_" or Mid(t, i, 1) = "-" or isnumeric(Mid(t, i, 1)) Then
' Capitalize words preceded by a space, a dot, a dash, an underscore, or a number
t = Mid(t, 1, i) & UCase(Mid(t, i + 1, 1)) & Mid(t, i+2, Len(t))
End If
Next
End If
Capitalize = t
End Function

Str

Views 4,049

Downloads 1,359

CodeID
DB ID