<p>How do I format a string to <a href="http://www.grammar-monster.com/lessons/capital_letters_title_case.htm" rel="noreferrer">title case</a>?</p>

[{'answer_id': 747, 'author': 'tags2k', 'author_id': 192, 'author_profile': 'https://Stackoverflow.com/users/192', 'pm_score': 4, 'selected': False, 'text': '<p>Here is a simple static method to do this in C#:</p>\n\n<pre><code>public static string ToTitleCaseInvariant(string targetString)\n{\n    return System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(targetString);\n}\n</code></pre>\n'}, {'answer_id': 749, 'author': 'cmcculloh', 'author_id': 58, 'author_profile': 'https://Stackoverflow.com/users/58', 'pm_score': 3, 'selected': False, 'text': '<p>In what language?</p>\n\n<p>In PHP it is:</p>\n\n<p><a href="http://php.net/manual/en/function.ucwords.php" rel="nofollow noreferrer">ucwords()</a></p>\n\n<p>example:</p>\n\n<pre><code>$HelloWorld = ucwords(\'hello world\');\n</code></pre>\n'}, {'answer_id': 751, 'author': 'Rudd Zwolinski', 'author_id': 219, 'author_profile': 'https://Stackoverflow.com/users/219', 'pm_score': -1, 'selected': False, 'text': '<p>Without using a ready-made function, a super-simple low-level algorithm to convert a string to title case:</p>\n\n<p><pre><code>\nconvert first character to uppercase.\nfor each character in string,\n    if the previous character is whitespace,\n        convert character to uppercase.\n</pre></code></p>\n\n<p>This asssumes the "convert character to uppercase" will do that correctly regardless of whether or not the character is case-sensitive (e.g., \'+\').</p>\n'}, {'answer_id': 754, 'author': 'Lehane', 'author_id': 142, 'author_profile': 'https://Stackoverflow.com/users/142', 'pm_score': 3, 'selected': False, 'text': '<p>If the language you are using has a supported method/function then just use that (as in the C# <code>ToTitleCase</code> method)</p>\n\n<p>If it does not, then you will want to do something like the following:  </p>\n\n<ol>\n<li>Read in the string  </li>\n<li>Take the first word  </li>\n<li>Capitalize the first letter of that word <sup>1</sup></li>\n<li>Go forward and find the next word  </li>\n<li>Go to 3 if not at the end of the string, otherwise exit  </li>\n</ol>\n\n<p><sup>1</sup> To capitalize it in, say, C - use the <a href="http://www.asciitable.com" rel="nofollow noreferrer">ascii codes</a> to find the integer value of the char and subtract 32 from it.</p>\n\n<p>There would need to be much more error checking in the code (ensuring valid letters etc.), and the "Capitalize" function will need to impose some sort of "title-case scheme" on the letters to check for words that do not need to be capatilised (\'and\', \'but\' etc. <a href="http://answers.google.com/answers/threadview?id=349913" rel="nofollow noreferrer">Here</a> is a good scheme)</p>\n'}, {'answer_id': 771, 'author': 'engtech', 'author_id': 175, 'author_profile': 'https://Stackoverflow.com/users/175', 'pm_score': 3, 'selected': False, 'text': '<p>Here\'s a Perl solution <a href="http://daringfireball.net/2008/05/title_case" rel="noreferrer">http://daringfireball.net/2008/05/title_case</a></p>\n\n<p>Here\'s a Ruby solution <a href="http://frankschmitt.org/projects/title-case" rel="noreferrer">http://frankschmitt.org/projects/title-case</a></p>\n\n<p>Here\'s a Ruby one-liner solution: <a href="http://snippets.dzone.com/posts/show/4702" rel="noreferrer">http://snippets.dzone.com/posts/show/4702</a></p>\n\n<pre><code>\'some string here\'.gsub(/\\b\\w/){$&amp;.upcase}\n</code></pre>\n\n<p>What the one-liner is doing is using a regular expression substitution of the first character of each word with the uppercase version of it.</p>\n'}, {'answer_id': 795, 'author': 'Ishmaeel', 'author_id': 227, 'author_profile': 'https://Stackoverflow.com/users/227', 'pm_score': 4, 'selected': False, 'text': '<p>I would be wary of automatically upcasing all whitespace-preceded-words in scenarios where I would run the risk of attracting the fury of nitpickers.</p>\n\n<p>I would at least consider implementing a dictionary for exception cases like articles and conjunctions. Behold: </p>\n\n<blockquote>\n  <p>"Beauty and the Beast"</p>\n</blockquote>\n\n<p>And when it comes to proper nouns, the thing gets much uglier.</p>\n'}, {'answer_id': 1595, 'author': 'Bill', 'author_id': 102, 'author_profile': 'https://Stackoverflow.com/users/102', 'pm_score': 3, 'selected': False, 'text': '<blockquote>\n  <p>To capatilise it in, say, C - use the ascii codes (<a href="http://www.asciitable.com/" rel="noreferrer">http://www.asciitable.com/</a>) to find the integer value of the char and subtract 32 from it.</p>\n</blockquote>\n\n<p>This is a poor solution if you ever plan to accept characters beyond a-z and A-Z.</p>\n\n<p>For instance: ASCII 134: å, ASCII 143: Å.<br>\nUsing arithmetic gets you: ASCII 102: f</p>\n\n<p>Use library calls, don\'t assume you can use integer arithmetic on your characters to get back something useful.  Unicode is <a href="http://www.joelonsoftware.com/articles/Unicode.html" rel="noreferrer">tricky</a>.</p>\n'}, {'answer_id': 71282, 'author': 'robbiebow', 'author_id': 11782, 'author_profile': 'https://Stackoverflow.com/users/11782', 'pm_score': -1, 'selected': False, 'text': "<p>With perl you could do this:</p>\n\n<pre><code>my $tc_string = join ' ', map { ucfirst($\\_) } split /\\s+/, $string;\n</code></pre>\n"}, {'answer_id': 151018, 'author': 'Randal Schwartz', 'author_id': 22483, 'author_profile': 'https://Stackoverflow.com/users/22483', 'pm_score': 3, 'selected': False, 'text': "<p>In Perl:</p>\n\n<pre><code>$string =~ s/(\\w+)/\\u\\L$1/g;\n</code></pre>\n\n<p>That's even in the FAQ.</p>\n"}, {'answer_id': 151181, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': -1, 'selected': False, 'text': '<p>Here you have a C++ version. It\'s got a set of non uppercaseable words like prononuns and prepositions. However, I would not recommend automating this process if you are to deal with important texts.</p>\n\n<pre><code>#include &lt;iostream&gt;\n#include &lt;string&gt;\n#include &lt;vector&gt;\n#include &lt;cctype&gt;\n#include &lt;set&gt;\n\nusing namespace std;\n\ntypedef vector&lt;pair&lt;string, int&gt; &gt; subDivision;\nset&lt;string&gt; nonUpperCaseAble;\n\nsubDivision split(string &amp; cadena, string delim = " "){\n    subDivision retorno;\n    int pos, inic = 0;\n    while((pos = cadena.find_first_of(delim, inic)) != cadena.npos){\n        if(pos-inic &gt; 0){\n            retorno.push_back(make_pair(cadena.substr(inic, pos-inic), inic));\n        }\n        inic = pos+1;\n    }\n    if(inic != cadena.length()){\n        retorno.push_back(make_pair(cadena.substr(inic, cadena.length() - inic), inic));\n    }\n    return retorno;\n}\n\nstring firstUpper (string &amp; pal){\n    pal[0] = toupper(pal[0]);\n    return pal;\n}\n\nint main()\n{\n    nonUpperCaseAble.insert("the");\n    nonUpperCaseAble.insert("of");\n    nonUpperCaseAble.insert("in");\n    // ...\n\n    string linea, resultado;\n    cout &lt;&lt; "Type the line you want to convert: " &lt;&lt; endl;\n    getline(cin, linea);\n\n    subDivision trozos = split(linea);\n    for(int i = 0; i &lt; trozos.size(); i++){\n        if(trozos[i].second == 0)\n        {\n            resultado += firstUpper(trozos[i].first);\n        }\n        else if (linea[trozos[i].second-1] == \' \')\n        {\n            if(nonUpperCaseAble.find(trozos[i].first) == nonUpperCaseAble.end())\n            {\n                resultado += " " + firstUpper(trozos[i].first);\n            }else{\n                resultado += " " + trozos[i].first;\n            }\n        }\n        else\n        {\n            resultado += trozos[i].first;\n        }       \n    }\n\n    cout &lt;&lt; resultado &lt;&lt; endl;\n    getchar();\n    return 0;\n}\n</code></pre>\n'}, {'answer_id': 1861303, 'author': 'user226515', 'author_id': 226515, 'author_profile': 'https://Stackoverflow.com/users/226515', 'pm_score': 1, 'selected': False, 'text': '<p>I think using the CultureInfo is not always reliable, this the simple and handy way to manipulate string manually:</p>\n<pre><code>string sourceName = txtTextBox.Text.ToLower();\nstring destinationName = sourceName[0].ToUpper();\n\nfor (int i = 0; i &lt; (sourceName.Length - 1); i++) {\n  if (sourceName[i + 1] == &quot;&quot;)  {\n    destinationName += sourceName[i + 1];\n  }\n  else {\n    destinationName += sourceName[i + 1];\n  }\n}\ntxtTextBox.Text = desinationName;\n</code></pre>\n'}, {'answer_id': 3003034, 'author': 'Simon_Weaver', 'author_id': 16940, 'author_profile': 'https://Stackoverflow.com/users/16940', 'pm_score': 1, 'selected': False, 'text': "<p>There is a built-in formula <code>PROPER(n)</code> in Excel.</p>\n\n<p>Was quite pleased to see I didn't have to write it myself!</p>\n"}, {'answer_id': 3003038, 'author': 'Simon_Weaver', 'author_id': 16940, 'author_profile': 'https://Stackoverflow.com/users/16940', 'pm_score': 2, 'selected': False, 'text': '<p><code>http://titlecase.com/</code> has an <a href="http://titlecase.com" rel="nofollow noreferrer">API</a></p>\n'}, {'answer_id': 3003080, 'author': 'Simon_Weaver', 'author_id': 16940, 'author_profile': 'https://Stackoverflow.com/users/16940', 'pm_score': 3, 'selected': False, 'text': '<p>In Silverlight there is no <code>ToTitleCase</code> in the <code>TextInfo</code> class.</p>\n\n<p>Here\'s a simple regex based way. </p>\n\n<p>Note: Silverlight doesn\'t have precompiled regexes, but for me this performance loss is not an issue.</p>\n\n<pre><code>    public string TitleCase(string str)\n    {\n        return Regex.Replace(str, @"\\w+", (m) =&gt;\n        {\n            string tmp = m.Value;\n            return char.ToUpper(tmp[0]) + tmp.Substring(1, tmp.Length - 1).ToLower();\n        });\n    }\n</code></pre>\n'}, {'answer_id': 5174338, 'author': 'rumbu', 'author_id': 642072, 'author_profile': 'https://Stackoverflow.com/users/642072', 'pm_score': 2, 'selected': False, 'text': '<p>Excel-like PROPER:</p>\n\n<pre><code>public static string ExcelProper(string s) {\n    bool upper_needed = true;\n    string result = "";\n    foreach (char c in s) {\n        bool is_letter = Char.IsLetter(c);\n        if (is_letter)\n            if (upper_needed)\n                result += Char.ToUpper(c);\n            else\n                result += Char.ToLower(c);\n        else\n            result += c;\n        upper_needed = !is_letter;\n    }\n    return result;\n}\n</code></pre>\n'}, {'answer_id': 13449709, 'author': 'goji', 'author_id': 269469, 'author_profile': 'https://Stackoverflow.com/users/269469', 'pm_score': 1, 'selected': False, 'text': '<p>Here\'s an implementation in Python: <a href="https://launchpad.net/titlecase.py" rel="nofollow">https://launchpad.net/titlecase.py</a></p>\n\n<p>And a port of this implementation that I\'ve just done in C++: <a href="http://codepad.org/RrfcsZzO" rel="nofollow">http://codepad.org/RrfcsZzO</a></p>\n'}, {'answer_id': 35744634, 'author': 'Ritesh Shakya', 'author_id': 5452950, 'author_profile': 'https://Stackoverflow.com/users/5452950', 'pm_score': 3, 'selected': False, 'text': "<p>In Java, you can use the following code.</p>\n\n<pre><code>public String titleCase(String str) {\n    char[] chars = str.toCharArray();\n    for (int i = 0; i &lt; chars.length; i++) {\n        if (i == 0) {\n            chars[i] = Character.toUpperCase(chars[i]);\n        } else if ((i + 1) &lt; chars.length &amp;&amp; chars[i] == ' ') {\n            chars[i + 1] = Character.toUpperCase(chars[i + 1]);\n        }\n    }\n    return new String(chars);\n}\n</code></pre>\n"}, {'answer_id': 47831875, 'author': 'Simony', 'author_id': 9019502, 'author_profile': 'https://Stackoverflow.com/users/9019502', 'pm_score': 1, 'selected': False, 'text': '<p>Here is a simple example of how to do it :</p>\n\n<pre><code>public static string ToTitleCaseInvariant(string str)\n{\n    return System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(str);\n}\n</code></pre>\n'}, {'answer_id': 58643270, 'author': 'Avid Programmer', 'author_id': 3992001, 'author_profile': 'https://Stackoverflow.com/users/3992001', 'pm_score': 0, 'selected': False, 'text': '<p>In C#</p>\n\n<pre><code>using System.Globalization;  \nusing System.Threading;  \nprotected void Page_Load(object sender, EventArgs e)  \n{  \n  CultureInfo cultureInfo   = Thread.CurrentThread.CurrentCulture;  \n  TextInfo textInfo = cultureInfo.TextInfo;  \n  Response.Write(textInfo.ToTitleCase("WelcometoHome&lt;br /&gt;"));  \n  Response.Write(textInfo.ToTitleCase("Welcome to Home"));  \nResponse.Write(textInfo.ToTitleCase("Welcome@to$home&lt;br/&gt;").Replace("@","").Replace("$", ""));  \n}\n</code></pre>\n'}, {'answer_id': 65265979, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>In C# you can simply use</p>\n<pre><code>CultureInfo.InvariantCulture.TextInfo.ToTitleCase(str.ToLowerInvariant())\n</code></pre>\n<ul>\n<li>Invariant</li>\n<li>Works with uppercase strings</li>\n</ul>\n'}]
['https://Stackoverflow.com/questions/746', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/192/']