Converting Strings To Title Case

I’ll present this tip the VB3 way and the VB4 way. I beat myself fora couple of hours over this routine to convert a string to Title Case.I used this with VB3:

 Function TCase(StrInp As String)Dim strout$Dim x%StrInp$ = LCase$(StrInp$)strout$ = UCase$(Left(StrInp$, 1))For x% = 2 To Len(StrInp$)	Select Case Asc(Mid$(StrInp$, x, 1))		Case Is < 97, Is > 122			strout$ = strout$ & Mid$(StrInp$, x, 1)		Case 97 To 122			Select Case Asc(Mid$(StrInp$, x - 1, 1))		Case 97 To 122			strout$ = strout$ & _				Mid$(StrInp$, x, 1)		Case Else: strout$ = _			strout$ & UCase$(Mid$(StrInp$, x, 1))	End SelectEnd SelectNextTCase = strout$End Function

In VB4, one line replaces the whole function:

 StrConv(string, vbProperCase)'Where vbProperCase is a built in constant in VB4
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: