Title case คือข้อความใดๆ เช่น ในหัวเรื่องหรือหัวเรื่อง โดยที่อักษรตัวแรกของคำสำคัญเป็นตัวพิมพ์ใหญ่ Title case หรือ headline case เป็นรูปแบบการใช้อักษรตัวพิมพ์ใหญ่สำหรับแสดงชื่อผลงานที่ตีพิมพ์หรือผลงานศิลปะเป็นภาษาอังกฤษ เมื่อใช้ตัวพิมพ์ใหญ่ขึ้นต้นคำทุกคำจะใช้ตัวพิมพ์ใหญ่ ยกเว้นคำ "เล็กน้อย" เว้นแต่จะเป็นคำแรกหรือคำสุดท้ายของ ชื่อเรื่อง.
การใช้งาน ToTitleCase ในปัจจุบันในตัวอย่างทำให้ได้สตริงเอาต์พุตที่มีความยาวเท่ากับสตริงอินพุต
ตัวอย่างที่ 1
class Program{
static void Main(string[] args){
string myString = "wAr aNd pEaCe";
TextInfo myTI = new CultureInfo("en-US", false).TextInfo;
Console.WriteLine("\"{0}\" to titlecase: {1}", myString, myTI.ToTitleCase(myString));
Console.ReadLine();
}
} ผลลัพธ์
"war and peace" to titlecase: War And Peace
ตัวอย่างที่ 2
class Program{
static void Main(string[] args){
string[] values = {
"a tale of three cities", "gROWL rescue",
"inside the office", "sports and tennis",
"The Return of Christmas Holmes"
};
TextInfo ti = CultureInfo.CurrentCulture.TextInfo;
foreach (var value in values)
Console.WriteLine("{0} −−> {1}", value, ti.ToTitleCase(value));
Console.ReadLine();
}
} ผลลัพธ์
a tale of three cities −−> A Tale Of Three Cities gROWL rescue −−> Growl Rescue inside the office −−> Inside The Office sports and tennis −−> Sports And Tennis The Return of Christmas Holmes −−> The Return Of Christmas Holmes