How to convert a string to title case in C#

3 Answers

0 votes
using System;
using System.Globalization;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "converts a STRING to title CASE IN c#";

            TextInfo ti = new CultureInfo("en-US", false).TextInfo;
            s = ti.ToTitleCase(s.ToLower());  // Converts A String To Title Case In C#
            Console.WriteLine(s);
        }
    }
}

/*
run:
 
Converts A String To Title Case In C#

*/


answered Feb 22, 2015 by avibootz
0 votes
using System;
using System.Globalization;
 
namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            TextInfo textInfo = CultureInfo.CurrentCulture.TextInfo; 
 
            string s1 = "star wars: the force awakens";
            string s2 = "star wars 2015: the force awakens";
            string s3 = "star WARS";
 
            s1 = textInfo.ToTitleCase(s1);
            s2 = textInfo.ToTitleCase(s2);
            s3 = textInfo.ToTitleCase(s3);
 
            Console.WriteLine(s1);
            Console.WriteLine(s2);
            Console.WriteLine(s3);
        }
    }
}
 
 
/*
run:
  
Star Wars: The Force Awakens
Star Wars 2015: The Force Awakens
Star WARS
 
*/

 



answered Dec 30, 2016 by avibootz
0 votes
using System;
using System.Globalization;
 
namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
 
            string s1 = "star wars: the force awakens";
            string s2 = "star wars 2015: the force awakens";
            string s3 = "star WARS";
 
            s1 = textInfo.ToTitleCase(s1);
            s2 = textInfo.ToTitleCase(s2);
            s3 = textInfo.ToTitleCase(s3);
 
            Console.WriteLine(s1);
            Console.WriteLine(s2);
            Console.WriteLine(s3);
        }
    }
}
 
 
/*
run:
  
Star Wars: The Force Awakens
Star Wars 2015: The Force Awakens
Star WARS
 
*/

 



answered Dec 30, 2016 by avibootz
...