|
-
May 17th, 2013, 06:25 AM
#1
Thread Starter
Fanatic Member
[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
-
May 17th, 2013, 06:28 AM
#2
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.
-
May 17th, 2013, 06:34 AM
#3
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!
-
May 17th, 2013, 06:40 AM
#4
Thread Starter
Fanatic Member
Re: Mix Of Uppercase And LowerCase
-
May 17th, 2013, 06:51 AM
#5
Re: [RESOLVED] Mix Of Uppercase And LowerCase
Code:
Dim s As String = "ABC DEF"
MsgBox(StrConv(s, VbStrConv.ProperCase))
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 17th, 2013, 06:54 AM
#6
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
Last edited by ident; May 17th, 2013 at 07:03 AM.
-
May 17th, 2013, 08:32 AM
#7
Thread Starter
Fanatic Member
Re: [RESOLVED] Mix Of Uppercase And LowerCase
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|