Custom Search
Logiclabz
  • Home
  • C#
  • Title case (Proper case) Function in .Net C#

Title case (Proper case) Function in .Net C#

  

The following function in .Net C# changes the string to its equivalent Title Case.

    public static string ToTitleCase(string mText)
    {
        string rText = "";
        try
        {
            System.Globalization.CultureInfo cultureInfo = 
System.Threading.Thread.CurrentThread.CurrentCulture;
            System.Globalization.TextInfo TextInfo = cultureInfo.TextInfo;
            rText = TextInfo.ToTitleCase(mText);
        }
        catch
        {
            rText = mText;
        }
        return rText;
    }



  


Leave a reply


Comments

  • madhu says:
    Apr 16, 10

    its not working if the input string in uppercase is there any solution Thanks in advance

  • NickG says:
    May 20, 10

    @madhu Hate to stat the obvious but why not just call .ToLower() on it first? :)

  • NickG says:
    May 20, 10

    @madhu Hate to state the obvious but why not just call .ToLower() on it first? :)

  • Sean says:
    Jul 14, 10

    @NickG ... Hate to state the obvious, but stat is spelled state :P

  • Michael Freidgeim says:
    Aug 17, 10

    You should add .ToLower() to the body of the function in the post

  • Hupperware says:
    Aug 27, 11

    Way too long... public static string ToTitleCase(this string aString) { try { return System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(aString); } catch { return aString; } }

  • Anna says:
    Jan 16, 12

    Thanks for your guides. it's really helpful. and i'm studying [URL="http://www.keepautomation.com/guide/csharp_barcode_generator.html"]C# Barcode Generation [/URL]too. that's also helpful. thanks both of you!

  • Anna says:
    Jan 16, 12

    Thanks for your guides. it's really helpful. and i'm studying C# Barcode Generation. that's also helpful. http://www.keepautomation.com/guide/csharp_barcode_generator.html

  • Anna says:
    Jan 16, 12

    Thanks for your guides. it's really helpful. and i'm studying C# Barcode Generation. that's also helpful. http://www.keepautomation.com/guide/csharp_barcode_generator.html



Do you like this post?