<?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/"
	
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Get Set Games &#187; NSString</title>
	<atom:link href="http://getsetgames.com/tag/nsstring/feed/" rel="self" type="application/rss+xml" />
	<link>http://getsetgames.com</link>
	<description></description>
	<lastBuildDate>Thu, 09 Sep 2010 15:15:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/><cloud domain='getsetgames.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<link rel="http://api.friendfeed.com/2008/03#sup" xmlns="http://www.w3.org/2005/Atom" type="application/json" href="http://friendfeed.com/api/public-sup.json#5c973c50be"/>		<item>
		<title>How to Format an NSString</title>
		<link>http://getsetgames.com/2009/12/19/iphonedev-advent-tip-19-how-to-format-an-nsstring/</link>
		<comments>http://getsetgames.com/2009/12/19/iphonedev-advent-tip-19-how-to-format-an-nsstring/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 03:08:02 +0000</pubDate>
		<dc:creator>Derek van Vliet</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[advent]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[NSString]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://getsetgames.com/?p=1010</guid>
		<description><![CDATA[It&#8217;s back to basics with today&#8217;s advent tip. I would be surprised if anything short of ALL developers have had a need to format strings at one time or another. iPhone app development is no exception. String formatting allows you to build a string based on a template and varying types of values. For example, [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s back to basics with today&#8217;s advent tip. I would be surprised if anything short of ALL developers have had a need to format strings at one time or another. iPhone app development is no exception.</p>
<p>String formatting allows you to build a string based on a template and varying types of values. For example, if I am keeping track of a player&#8217;s score as an integer and I want to display a string to the player that celebrates their score by saying &#8220;You scored 2600! Way to go!&#8221;, then I need string formatting to get the correct score in the middle of that string.</p>
<h2>How to Do It</h2>
<p>Below is an example of how to build the above NSString. This example formats a string with an integer in it using the <strong>%i</strong> format specifier.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">int</span> score <span style="color: #002200;">=</span> <span style="color: #2400d9;">2600</span>;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span> scoreString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;You scored %i! Way to go!&quot;</span>,score<span style="color: #002200;">&#93;</span>;</pre></div></div>

<h2>Format Specifiers</h2>
<p>But string formatting doesn&#8217;t stop at putting integers in strings. Below are some of the most common format specifiers for other value types:</p>
<table>
<tr>
<td><strong>Specifier</strong></td>
<td><strong>Purpose</strong></td>
</tr>
<tr>
<td>%i</td>
<td>integer</td>
</tr>
<tr>
<td>%f</td>
<td>float</td>
</tr>
<tr>
<td>%@</td>
<td>Objective-C object (commonly used to specify another NSString)</td>
</tr>
<tr>
<td>%x</td>
<td>hexadecimal</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://getsetgames.com/2009/12/19/iphonedev-advent-tip-19-how-to-format-an-nsstring/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
	</item>
		<item>
		<title>String Comparison Using NSString</title>
		<link>http://getsetgames.com/2009/12/10/iphonedev-advent-tip-10-string-comparison-using-nsstring/</link>
		<comments>http://getsetgames.com/2009/12/10/iphonedev-advent-tip-10-string-comparison-using-nsstring/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 23:02:03 +0000</pubDate>
		<dc:creator>Derek van Vliet</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[advent]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[NSString]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://getsetgames.com/?p=932</guid>
		<description><![CDATA[One of the most common things a programmer needs to learn how to do when faced with a new API is how to compare one string to another to see if the two are the same or how they differ. Because of this, many APIs have created some handy string comparison features, and the NSString [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://getsetgames.com/wp-content/uploads/2009/12/Photo-2a.jpg" alt="Photo-2a" title="Photo-2a" width="500" height="375" class="aligncenter size-full wp-image-935" /></p>
<p>One of the most common things a programmer needs to learn how to do when faced with a new API is how to compare one string to another to see if the two are the same or how they differ.</p>
<p>Because of this, many APIs have created some handy string comparison features, and the NSString class in objective-c is no exception. What follows are some invaluable tools for string comparison in objective-c.</p>
<h2>The Is-Equal Method</h2>
<p>The NSString class responds to a message and returns whether or not the NSString you pass in is equal or not:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span> str <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;oranges&quot;</span>;
<span style="color: #a61390;">BOOL</span> res <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>str isEqualToString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;apples&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<h2>The Compare Method</h2>
<p>The NSString class also has a method called compare, which gives you a bit more info in the return results. It can actually tell you the difference between the two strings; whether or not the string you passed in is:</p>
<ul>
<li>the same,</li>
<li>in ascending sort order to the string you call the message on or</li>
<li>in descending sort order to the string you call the message on</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span> str <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;oranges&quot;</span>;
NSComparisonResult res <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>str compare<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;apples&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #a61390;">switch</span> <span style="color: #002200;">&#40;</span>res<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">case</span> NSOrderedAscending<span style="color: #002200;">:</span>
		<span style="color: #11740a; font-style: italic;">// going up</span>
		<span style="color: #a61390;">break</span>;
	<span style="color: #a61390;">case</span> NSOrderedSame<span style="color: #002200;">:</span>
		<span style="color: #11740a; font-style: italic;">// even steven</span>
		<span style="color: #a61390;">break</span>;
	<span style="color: #a61390;">case</span> NSOrderedDescending<span style="color: #002200;">:</span>
		<span style="color: #11740a; font-style: italic;">// down i go</span>
		<span style="color: #a61390;">break</span>;
	<span style="color: #a61390;">default</span><span style="color: #002200;">:</span>
		<span style="color: #a61390;">break</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<h2>Insensitivity to Case</h2>
<p>Finally, the NSString class also features a method for comparing strings without case sensitivity. This is useful for comparing strings with unpredictable case, such as user input. Like the compare method, it returns an NSComparisonResult enumerated value which allows you to see the equality or sort-order of the two strings.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span> str <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;APPLES&quot;</span>;
NSComparisonResult res <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>str caseInsensitiveCompare<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;apples&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #a61390;">switch</span> <span style="color: #002200;">&#40;</span>res<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">case</span> NSOrderedAscending<span style="color: #002200;">:</span>
		<span style="color: #11740a; font-style: italic;">// onward and upward</span>
		<span style="color: #a61390;">break</span>;
	<span style="color: #a61390;">case</span> NSOrderedSame<span style="color: #002200;">:</span>
		<span style="color: #11740a; font-style: italic;">// same old</span>
		<span style="color: #a61390;">break</span>;
	<span style="color: #a61390;">case</span> NSOrderedDescending<span style="color: #002200;">:</span>
		<span style="color: #11740a; font-style: italic;">// downfall</span>
		<span style="color: #a61390;">break</span>;
	<span style="color: #a61390;">default</span><span style="color: #002200;">:</span>
		<span style="color: #a61390;">break</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://getsetgames.com/2009/12/10/iphonedev-advent-tip-10-string-comparison-using-nsstring/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:thumbnail url="http://getsetgames.com/wp-content/uploads/2009/12/Photo-2a-150x150.jpg" />
		<media:content url="http://getsetgames.com/wp-content/uploads/2009/12/Photo-2a.jpg" medium="image">
			<media:title type="html">Photo-2a</media:title>
			<media:thumbnail url="http://getsetgames.com/wp-content/uploads/2009/12/Photo-2a-150x150.jpg" />
		</media:content>
	</item>
	</channel>
</rss>
