Skip to main content
.NET Framework Class Library
TextInfoToTitleCase Method

Converts the specified string to title case (except for words that are entirely in uppercase, which are considered to be acronyms).

Namespace:   System.Globalization
Assembly:  mscorlib (in mscorlib.dll)
Syntax
Public Function ToTitleCase ( _
	str As [%$TOPIC/cy44dx26_en-us_VS_110_1_0_0_0_0%] _
) As [%$TOPIC/cy44dx26_en-us_VS_110_1_0_0_0_1%]
public [%$TOPIC/cy44dx26_en-us_VS_110_1_0_1_0_0%] ToTitleCase(
	[%$TOPIC/cy44dx26_en-us_VS_110_1_0_1_0_1%] str
)
public:
[%$TOPIC/cy44dx26_en-us_VS_110_1_0_2_0_0%]^ ToTitleCase(
	[%$TOPIC/cy44dx26_en-us_VS_110_1_0_2_0_1%]^ str
)
member ToTitleCase : 
        str:[%$TOPIC/cy44dx26_en-us_VS_110_1_0_3_0_0%] -> [%$TOPIC/cy44dx26_en-us_VS_110_1_0_3_0_1%]

Parameters

str
Type: SystemString

The string to convert to title case.

Return Value

Type: SystemString
The specified string converted to title case.
Exceptions
ExceptionCondition
ArgumentNullException

str is .

Remarks

Generally, title casing converts the first character of a word to uppercase and the rest of the characters to lowercase. However, this method does not currently provide proper casing to convert a word that is entirely uppercase, such as an acronym. The following table shows the way the method renders several strings.

Input

Language

Expected result

Actual result

war and peace

English

War and Peace

War And Peace

Per anhalter durch die Galaxis

German

Per Anhalter durch die Galaxis

Per Anhalter Durch Die Galaxis

les naufragés d'ythaq

French

Les Naufragés d'Ythaq

Les Naufragés D'ythaq

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.

Examples

The following example changes the casing of a string based on the English (United States) culture, with the culture name en-US.

Imports System
Imports System.Globalization

Public Class SamplesTextInfo

   Public Shared Sub Main()

      ' Defines the string with mixed casing. 
      Dim myString As String = "wAr aNd pEaCe" 

      ' Creates a TextInfo based on the "en-US" culture. 
      Dim myTI As TextInfo = New CultureInfo("en-US", False).TextInfo

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

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

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

   End Sub 'Main 

End Class 'SamplesTextInfo


'This code produces the following output. 
' 
'"wAr aNd pEaCe" to lowercase: war and peace 
'"wAr aNd pEaCe" to uppercase: WAR AND PEACE 
'"wAr aNd pEaCe" to titlecase: War And Peace
using System;
using System.Globalization;


public class SamplesTextInfo  {

   public static void Main()  {

      // Defines the string with mixed casing. 
      string myString = "wAr aNd pEaCe";

      // Creates a TextInfo based on the "en-US" culture.
      TextInfo myTI = new CultureInfo("en-US",false).TextInfo;

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

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

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

   }

}

/*
This code produces the following output.

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

*/
using namespace System;
using namespace System::Globalization;
int main()
{

   // Defines the String* with mixed casing.
   String^ myString = "wAr aNd pEaCe";

   // Creates a TextInfo based on the S"en-US" culture.
   CultureInfo^ MyCI = gcnew CultureInfo( "en-US",false );
   TextInfo^ myTI = MyCI->TextInfo;

   // Changes a String* to lowercase.
   Console::WriteLine( "\"{0}\" to lowercase: {1}", myString, myTI->ToLower( myString ) );

   // Changes a String* to uppercase.
   Console::WriteLine( "\"{0}\" to uppercase: {1}", myString, myTI->ToUpper( myString ) );

   // Changes a String* to titlecase.
   Console::WriteLine( "\"{0}\" to titlecase: {1}", myString, myTI->ToTitleCase( myString ) );
}

/*
This code produces the following output.

S"wAr aNd pEaCe" to lowercase: war and peace
S"wAr aNd pEaCe" to uppercase: WAR AND PEACE
S"wAr aNd pEaCe" to titlecase: War And Peace

*/

The following example passes each string in an array to the ToTitleCase method. The strings include proper title strings as well as acronyms. The strings are converted to title case by using the conventions of the en-US culture.

Imports System.Globalization

Module Example
   Public Sub Main()
      Dim values() As String = { "a tale of two cities", "gROWL to the rescue",
                                 "inside the US government", "sports and MLB baseball",
                                 "The Return of Sherlock Holmes", "UNICEF and children"}

      Dim ti As TextInfo = CultureInfo.CurrentCulture.TextInfo
      For Each value In values
         Console.WriteLine("{0} --> {1}", value, ti.ToTitleCase(value))
      Next 
   End Sub 
End Module 
' The example displays the following output: 
'    a tale of two cities --> A Tale Of Two Cities 
'    gROWL to the rescue --> Growl To The Rescue 
'    inside the US government --> Inside The US Government 
'    sports and MLB baseball --> Sports And MLB Baseball 
'    The Return of Sherlock Holmes --> The Return Of Sherlock Holmes 
'    UNICEF and children --> UNICEF And Children
using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string[] values = { "a tale of two cities", "gROWL to the rescue",
                          "inside the US government", "sports and MLB baseball",
                          "The Return of Sherlock Holmes", "UNICEF and children"};

      TextInfo ti = CultureInfo.CurrentCulture.TextInfo;
      foreach (var value in values)
         Console.WriteLine("{0} --> {1}", value, ti.ToTitleCase(value));
   }
}
// The example displays the following output: 
//    a tale of two cities --> A Tale Of Two Cities 
//    gROWL to the rescue --> Growl To The Rescue 
//    inside the US government --> Inside The US Government 
//    sports and MLB baseball --> Sports And MLB Baseball 
//    The Return of Sherlock Holmes --> The Return Of Sherlock Holmes 
//    UNICEF and children --> UNICEF And Children
Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.