Community discussion forum

Proper Case Function

This is a comment thread discussing Proper Case Function
  • 10 years ago

    This thread is for discussions of Proper Case Function.

  • 8 years ago
    StrConv(string, vbProperCase) does this in VB 6.  Otherwise it's handy for versions 4/5.

    D
  • 6 years ago
    The code worked well on an ASP 3.0 project after some modifications.  One enhancement I added was checks for apostrophes within names (like O'Neal), and for apostrophe 's' at the end of a sentence.  Thanks!
  • 2 years ago

    Private Function FirstLetterCaps(str As String) As String
    Dim ExtractWord, NewStr As String
    Dim position As Integer
    position = InStr(str, " ")
    While position
        ExtractWord = LCase$(Left$(str, position))
        NewStr = NewStr & UCase$(Left$(ExtractWord, 1)) & Mid$(ExtractWord, 2)
        str = Right$(str, Len(str) - position)
        position = InStr(str, " ")
    Wend
        ExtractWord = LCase$(str)
        NewStr = NewStr & UCase$(Left$(ExtractWord, 1)) & Mid$(ExtractWord, 2)
        FirstLetterCaps = NewStr
    End Function












    Above function is called wth str argument passed to it. First word of the str is extracted by using Left$ function and changed to LCase for sure. Then First char of the extracted word is converted to UCase while remaining are retained as Lcase, and this word is added to Newstr. The str is then deducted of the first word using Right$ function. Position is moved to next space location. As the loop so performed, the Newstr continuously accumulates words while str looses them until str is left with last word whose first char is finally converted to UCase and added to Newstr. The Newstr thus is formed with  First Chars UCase which is then returned to calling procedure.

    Note: With VB6, StrConv(string, vbProperCase)  function performs the same task in a single line of code with effortless ease.

  • 2 years ago

    Simplest One.

    Text1.Text = StrConv(Text1.Text, vbProperCase)

  • 2 years ago
    A bit simpler... INITCAP
  • 5 months ago

    .net equivalent:

    System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase()

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback