<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Geekality &#187; String</title>
	<atom:link href="http://www.geekality.net/tag/string/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.geekality.net</link>
	<description>With a hint of Social Ineptitude</description>
	<lastBuildDate>Sun, 05 Feb 2012 17:53:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>JavaScript: Uppercase first letter in a string</title>
		<link>http://www.geekality.net/2010/06/30/javascript-uppercase-first-letter-in-a-string/</link>
		<comments>http://www.geekality.net/2010/06/30/javascript-uppercase-first-letter-in-a-string/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 13:21:07 +0000</pubDate>
		<dc:creator>Torleif</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://www.geekality.net/?p=1052</guid>
		<description><![CDATA[In PHP there is a very handy function called ucfirst which Returns a string with the first character of str capitalized, if that character is alphabetic. Needed that in JavaScript, but discovered there was no such thing. Luckily I quickly &#8230; <a href="http://www.geekality.net/2010/06/30/javascript-uppercase-first-letter-in-a-string/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In PHP there is a very handy function called <a href="http://php.net/ucfirst">ucfirst</a> which </p>
<blockquote><p>Returns a string with the first character of str capitalized, if that character is alphabetic.</p></blockquote>
<p>Needed that in JavaScript, but discovered there was no such thing.</p>
<p><span id="more-1052"></span></p>
<p>Luckily I quickly found <a href="http://stackoverflow.com/q/1026069/39321#1026087">a function</a> over at StackOverflow that I adjusted slightly and added to the string class:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">ucfirst</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toUpperCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Can be used like so:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'some text'</span>.<span style="color: #660066;">ucfirst</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #006600; font-style: italic;">// Alerts: Some text</span></div></div>
<h2>Alternative CSS method</h2>
<p>In many cases it might be good to just handle this with CSS instead. For example, to uppercase the first letter in all list items, you can do this:</p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">li<span style="color: #3333ff;">:first-letter<br />
</span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">text-transform</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">uppercase</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></div>
<p>Weeee <img src='http://www.geekality.net/wp-includes/images/blank.gif' alt='^_^' class='wp-smiley smiley-9' /> Ok, back to work&#8230;</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.geekality.net/2010/06/30/javascript-uppercase-first-letter-in-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

