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;
    }


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


Leave a reply


Do you like this post?