[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
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)
Re: Mix Of Uppercase And LowerCase
What a horrible footnote at the bottom of that link on TitleCase
Quote:
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!
Re: Mix Of Uppercase And LowerCase
Re: [RESOLVED] Mix Of Uppercase And LowerCase
Code:
Dim s As String = "ABC DEF"
MsgBox(StrConv(s, VbStrConv.ProperCase))
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:
Imports System.Runtime.CompilerServices
Imports System.Globalization
<Extension()> _
Public Module TitleCaseExtension
Public Function TitleCase(ByVal message As String) As String
Return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(message)
End Function
End Module
Re: [RESOLVED] Mix Of Uppercase And LowerCase