[RESOLVED] First Letter Capital, Leave the rest-VBForums
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,256

    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
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,334

    Re: First Letter Capital, Leave the rest

    How about simply using vbProperCase?
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  5. #5

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

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.