Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Aug 6, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Converting Strings To Title Case

I'll present this tip the VB3 way and the VB4 way. I beat myself for a 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 Select
End Select
TCase = strout$
End Function
In VB4, one line replaces the whole function:
 StrConv(string, vbProperCase)

'Where vbProperCase is a built in constant in VB4
Jason Lee
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date