ToTitleCase method not working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following cod ein my base page:

Private tInfo As TextInfo = New CultureInfo("en-US", False).TextInfo

Protected Function TitleIt(ByVal input As String) As String
Return tInfo.ToTitleCase(input)
End Function

And I am implementing it like this:

UsersName.Text = TitleIt(currentUser.fullName)

And it simply isn't returning title cased stuff:

?Input
"WILLIAM SEMPF"
?TitleIt
"WILLIAM SEMPF"

I have noticed a few other recent unanswered posts around the 'net about
this. Recent service pack break Globalization? ToLower works just fine:

?Input
"WILLIAM SEMPF"
?TitleIt
"william sempf"

Thoughts welcome.

S
 
Private tInfo As TextInfo = New CultureInfo("en-US",
False).TextInfo

Protected Function TitleIt(ByVal input As String) As String
Return tInfo.ToTitleCase(input)
End Function

And I am implementing it like this:

UsersName.Text = TitleIt(currentUser.fullName)

And it simply isn't returning title cased stuff:

?Input
"WILLIAM SEMPF"
?TitleIt
"WILLIAM SEMPF"

Mhm... Your code works just fine on my German Windows XP Professional SP2 +
..NET 1.1 SP1 machine.
 
To me it looks like every word has to have one none capital letter, because
when I test it with this routine:
Dim myTI As System.Globalization.TextInfo = New
System.Globalization.CultureInfo("en-US", False).TextInfo

Console.WriteLine("""{0}"" to titlecase: {1}", "WAR AND PEACE",
myTI.ToTitleCase _
("WAR AND PEACE"))
Console.WriteLine("""{0}"" to titlecase: {1}", "war and peace",
myTI.ToTitleCase("war and peace"))
Console.WriteLine("""{0}"" to titlecase: {1}", "WaR aND PEaCE",
myTI.ToTitleCase("WaR aND PEaCE"))
Console.WriteLine("""{0}"" to titlecase: {1}", "WAR AND PEaCE",
myTI.ToTitleCase("WAR AND PEaCE"))


I get these results:

"WAR AND PEACE" to titlecase: WAR AND PEACE
"war and peace" to titlecase: War And Peace
"WaR aND PEaCE" to titlecase: War And Peace
"WAR AND PEaCE" to titlecase: WAR AND Peace

I'm running WIN2000 Pro SP4, framework 1.1

Greetz Peter
 
Herfried,

Is this a kind of punishment?

I am glad I know now that there is an alternative to the method from which I
always remember me forever a slightly long discussion between you an OHM.

:-)

Cor
 
Peter,

Do think that we use this in our culture, I cannot remember that I have ever
thought about this?

I make a tittle as it looks nice, not looking what kind of font, capital or
whatever is in it.

Therefore I remember me that proper case forever because I was suprised when
OHM showed that to us.

:-)

Cor
 
I indeed would use all Capital letters for a title or a "SentanceCase" ;-)

but I think the OP was expecting a Propercase behavior, as was I, but now I
see I misunderstood the function name. With toTitleCase I thought of a name
Title for example Mr. Peter Proost not a real title.

Greetz Peter
 
Peter,
Interesting.

I find the same thing on Windows XP SP2.

It seems that ToTitleCase doesn't change a word if the word is all upper
case...


--
Hope this helps
Jay
T.S. Bradley - http://www.tsbradley.net


| To me it looks like every word has to have one none capital letter,
because
| when I test it with this routine:
| Dim myTI As System.Globalization.TextInfo = New
| System.Globalization.CultureInfo("en-US", False).TextInfo
|
| Console.WriteLine("""{0}"" to titlecase: {1}", "WAR AND PEACE",
| myTI.ToTitleCase _
| ("WAR AND PEACE"))
| Console.WriteLine("""{0}"" to titlecase: {1}", "war and peace",
| myTI.ToTitleCase("war and peace"))
| Console.WriteLine("""{0}"" to titlecase: {1}", "WaR aND PEaCE",
| myTI.ToTitleCase("WaR aND PEaCE"))
| Console.WriteLine("""{0}"" to titlecase: {1}", "WAR AND PEaCE",
| myTI.ToTitleCase("WAR AND PEaCE"))
|
|
| I get these results:
|
| "WAR AND PEACE" to titlecase: WAR AND PEACE
| "war and peace" to titlecase: War And Peace
| "WaR aND PEaCE" to titlecase: War And Peace
| "WAR AND PEaCE" to titlecase: WAR AND Peace
|
| I'm running WIN2000 Pro SP4, framework 1.1
|
| Greetz Peter
|
|
|
|
|
|
| --
| Programming today is a race between software engineers striving to build
| bigger and better idiot-proof programs, and the Universe trying to produce
| bigger and better idiots. So far, the Universe is winning.
|
|
 
Jay B. Harlow said:
I find the same thing on Windows XP SP2.

It seems that ToTitleCase doesn't change a word if the word is all upper
case...

Yes, that's true. I am able to reproduce this behavior, and I think that it
is "by design".
 
Herfried,
Interesting StrConv works "as one might expect", however TextInfo "en-US"
does not work "as one might expect Proper Case to". ;-)


My current culture is "en-US".

Trying the sample from TextInfo.ToTitleCase:

Dim myTI As System.Globalization.TextInfo = New
System.Globalization.CultureInfo("en-US", False).TextInfo

myTI = System.Globalization.CultureInfo.CurrentCulture.TextInfo

' Changes a string to lowercase.
Console.WriteLine("""{0}"" to lowercase: {1}", myString,
myTI.ToTitleCase(myTI.ToLower(myString)))

' Changes a string to uppercase.
Console.WriteLine("""{0}"" to uppercase: {1}", myString,
myTI.ToTitleCase(myTI.ToUpper(myString)))

' Changes a string to titlecase.
Console.WriteLine("""{0}"" to titlecase: {1}", myString,
myTI.ToTitleCase(myString))

' Changes a string to lowercase.
Console.WriteLine("""{0}"" to lowercase: {1}", myString,
StrConv(myTI.ToLower(myString), VbStrConv.ProperCase))

' Changes a string to uppercase.
Console.WriteLine("""{0}"" to uppercase: {1}", myString,
StrConv(myTI.ToUpper(myString), VbStrConv.ProperCase))

' Changes a string to titlecase.
Console.WriteLine("""{0}"" to titlecase: {1}", myString,
StrConv(myString, VbStrConv.ProperCase))


I get:

"wAr aNd pEaCe" to lowercase: War And Peace
"wAr aNd pEaCe" to uppercase: WAR AND PEACE
"wAr aNd pEaCe" to titlecase: War And Peace
"wAr aNd pEaCe" to lowercase: War And Peace
"wAr aNd pEaCe" to uppercase: War And Peace
"wAr aNd pEaCe" to titlecase: War And Peace

The first three are ToTitleCase, while the next 3 are StrConv. I get the
same result for both CurrentCulture & New CultureInfo(en-US).

Reading the "fine print" at
http://msdn.microsoft.com/library/d...lobalizationTextInfoClassToTitleCaseTopic.asp I
can see how the function might decide that a word in all caps is "special"
and not convert it, as words in all caps are usually acronyms & you normally
don't want to change acronyms. HOWEVER! I'm really not sure where that would
be documented in relation to TextInfo.ToTitleCase...

--
Hope this helps
Jay
T.S. Bradley - http://www.tsbradley.net


| > To get the proper case you can be the way use that VisualBasic method
for
| > that.
| >
| >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctstrconv.asp
|
| 'StrConv' + 'vbProperCase' is a wrapper around 'TextInfo.ToTitleCase' too.
|
| --
| M S Herfried K. Wagner
| M V P <URL:http://dotnet.mvps.org/>
| V B <URL:http://classicvb.org/petition/>
|
 
guy said:
OHM?
do i detect some resistance?
Not att all, OHM is the nick in this newsgroup for One Handed Man, or better
Terry Burns, you see that name often in my old samples. Unluckely enough he
is a while now active.

:-)

Cor
 
Herfried said:
Yes, that's true. I am able to reproduce this behavior, and I think
that it is "by design".

That seems reasonable because an abbreviation like ISDN should always be in
uppercase, so a ToTitleCase transformation should leave it uppercase. If the
OP wants to force titlecase, then go via lowercase. Note however that some
names have letters which should never be in uppercase, e.g.
http://www.phys.uu.nl/~thooft/ap.html
For other problems, see
http://www.unicode.org/versions/Unicode4.0.0/ch05.pdf#G21180

Andrew
 
Jay,

Jay B. Harlow said:
Interesting StrConv works "as one might expect", however TextInfo "en-US"
does not work "as one might expect Proper Case to". ;-)

'StrConv' + 'ProperCase' will convert the text into lower case first
(p/invoke with 'LCMapString' ("kernel32.dll") + 'LCMAP_LOWERCASE'). I
missed that when doing my research using Reflector.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top