Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


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

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
Next
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.

 

 

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