[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

Capitalization code - 50 pts

Does anyone have code that will capitalize the first letter of each word in a string?  Thanks!
0
neymeyer
Asked:
neymeyer
1 Solution
 
VbmasterCommented:
It ought to look something like this


Function Capitalize(ByVal Value As String) As String

  Dim a As Long
  Dim LenValue As Long

  LenValue = Len(Value)

  Mid$(Value, 1, 1) = UCase$(Mid$(Value, 1, 1))
  For a = 1 To LenValue
    Select Case Mid$(Value, a, 1)
    Case " "
      If (a < LenValue) Then
        Mid$(Value, a + 1, 1) = UCase$(Mid$(Value, a + 1, 1))
      End If
    End Select
  Next
  Capitalize = Value

End Function


You can add more characters at the end of the Case line if you'd like, this function will upper-case the character after every space + the very first character in the string.
0
 
neymeyerAuthor Commented:
Awesome, Thanks a lot!
0
 
tureCommented:
neymeyer,

Here's another suggestion:

Function PCase(x As String) As String
  Dim p As Long
  PCase = Trim(LCase(x))
  Do
    Mid(PCase, p + 1, 1) = UCase(Mid(PCase, p + 1, 1))
    p = InStr(p + 1, PCase, " ")
  Loop Until p = 0
End Function

Ture Magnusson
Karlstad, Sweden
0
 
johnczimmCommented:
Have you tried StrConv?

StrConv(Text1.Text, vbProperCase)

JOHN
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now