Results 1 to 7 of 7

Thread: [RESOLVED] Mix Of Uppercase And LowerCase

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    Resolved [RESOLVED] Mix Of Uppercase And LowerCase

    I know how to covert a string to Upper case or lowercase using .ToUpper or .ToLower
    is there a built in function to create a string with the first letter in each word being uppercase and the remaining letters in the word being lowercase?

    I am sure (I may be wrong though) that there was such a function in VB6 for this

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Mix Of Uppercase And LowerCase

    Is it called TitleCase. Here is a link for the documentation
    http://msdn.microsoft.com/en-us/libr...otitlecase.asp

    Code:
            Dim myString As String = "wAr aNd pEaCe"
    
            Dim myTI As Globalization.TextInfo = New Globalization.CultureInfo(Globalization.CultureInfo.CurrentCulture.Name, False).TextInfo
    
            myString = myTI.ToTitleCase(myString)
    Last edited by dbasnett; May 17th, 2013 at 06:45 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Mix Of Uppercase And LowerCase

    What a horrible footnote at the bottom of that link on TitleCase

    As illustrated above, the ToTitleCase method provides an arbitrary casing behavior which is not necessarily linguistically correct. A linguistically correct solution would require additional rules, and the current algorithm is somewhat simpler and faster. We reserve the right to make this API slower in the future.

    The current implementation of the ToTitleCase method yields an output string that is the same length as the input string. However, this behavior is not guaranteed and could change in a future implementation.
    If this bothers you at all then write an unmanaged function in C++ and do it yourself!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    Re: Mix Of Uppercase And LowerCase

    Many Thanks

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: [RESOLVED] Mix Of Uppercase And LowerCase

    Code:
    Dim s As String = "ABC DEF"
    MsgBox(StrConv(s, VbStrConv.ProperCase))

  6. #6
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: Mix Of Uppercase And LowerCase

    *Edit , looks like i am a bit slow posting

    I still use vb6 *sigh*

    Code:
    Dim message As String = "the quick brown fox jumps over the lazy dog"
    MessageBox.Show(StrConv(message, VbStrConv.ProperCase))
    Another way would be to write your own extension method.

    vb Code:
    1. Imports System.Runtime.CompilerServices
    2. Imports System.Globalization
    3.  
    4. <Extension()> _
    5. Public Module TitleCaseExtension
    6.  
    7.     Public Function TitleCase(ByVal message As String) As String
    8.         Return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(message)
    9.     End Function
    10.  
    11. End Module
    Last edited by ident; May 17th, 2013 at 07:03 AM.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    Re: [RESOLVED] Mix Of Uppercase And LowerCase

    Thanks Guys

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