toTitleCase method missing?

Right, currently I want to convert some strings to title case (“face”->“Face”), however Unity seems to be missing this.

when I add

using System.Globalization;

In my c# script, I just get some the options to convert all the letters to lower/upper - am I doing something wrong?

Unity doesn’t use .NET, but MONO, the open source port of .NET Framework.

MONO 2.6 basically has the (approximate) feature set of .NET 3.0/3.5 minus Window Specific namespaces (i.e. no forms namespaces). But mono lags sometimes, so it’s probably something to do with mono itself.

If you use this to compare strings, you should rather use ToLower or ToUpper methods instead, as this is the preferred way of doing such string comparisons.

Also as you may have checked out the comments, the ToTitleCase doesn’t always result what users may expect and there is not even a guarantee it will stay the same in future. Imho this method was mainly added for ASP.NET, where you might want to format the title (hence the name of the method) of a page or news article, since it’s typical to show article/news title with all words with uppercase.

thanks! found a solution here:
http://www.velocityreviews.com/forums/t131690-regex-to-capitalize-first-letter-of-string.html

when adapted for unity (c#):

string ToTitleCase(string stringToConvert)
	{
		string firstChar= stringToConvert[0].ToString();
		return (stringToConvert.Length>0 ? firstChar.ToUpper()+stringToConvert.Substring(1) : stringToConvert);
		
	}

That’s actually not a title case you are scripting here. It is simply capitalizing the first letter of every word. True title case capitalizes the first letter only if it is an important word, omitting words such as “of,” “the,” “from” etc.