Results 1 to 5 of 5

Thread: [RESOLVED] First Letter Capital, Leave the rest

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258

    Resolved [RESOLVED] First Letter Capital, Leave the rest

    What code do i use to make the first letter capital but leave the rest of the letters alone (So i cant use StrConv because that converts all the other letters to lowercase).



    thIs shouLd BecomE


    ThIs ShouLd BecomE

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: First Letter Capital, Leave the rest

    This should work...

    vb Code:
    1. Dim sString As String
    2. Dim i As Integer
    3. Dim sInfo() As String
    4.  
    5. 'split your words by space
    6. sInfo = Split("thIs shouLd BecomE", " ")
    7.  
    8.     For i = 0 To UBound(sInfo)
    9.        
    10.         'check if it's already a capital
    11.         If Asc(Left$(sInfo(i), 1)) < 65 Or Asc(Left$(sInfo(i), 1)) > 90 Then
    12.        
    13.         sInfo(i) = Chr(Asc(Left$(sInfo(i), 1)) - 32) & Right$(sInfo(i), Len(sInfo(i)) - 1)
    14.                
    15.         End If
    16.        
    17.     sString = sString & sInfo(i) & " "
    18.    
    19.     Next
    20.  
    21. MsgBox sString

  3. #3
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: First Letter Capital, Leave the rest

    here is another one
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        MsgBox makeFirstUCase("thIs shouLd BecomE")
    End Sub
    
    
    Private Function makeFirstUCase(myStr As String) As String
        Dim strArr() As String
        Dim i As Integer
        
        strArr = Split(myStr, " ")
        For i = 0 To UBound(strArr)
            If strArr(i) <> vbNullString Then
                strArr(i) = UCase(Left$(strArr(i), 1)) & Right$(strArr(i), Len(strArr(i)) - 1)
            End If
            makeFirstUCase = makeFirstUCase & strArr(i) & " "
        Next
        
        
        
    End Function
    IIF(Post.Rate > 0 , , )

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: First Letter Capital, Leave the rest

    How about simply using vbProperCase?

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258

    Re: First Letter Capital, Leave the rest

    Thanks ZeeZee, Lintz.

    Hack
    Just read again the question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width