<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: string code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 12 Oct 2008 10:59:34 GMT</pubDate>
    <description>DZone Snippets: string code</description>
    <item>
      <title>Alphabetical sorter</title>
      <link>http://snippets.dzone.com/posts/show/2705</link>
      <description>// This function sorts an array of objects that include this code, alphabetically&lt;br /&gt;// That's nothing new, except this sorts strings starting with a number correctly!&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  # ---&lt;br /&gt;  # Sorting&lt;br /&gt;  # ---&lt;br /&gt;def &lt;=&gt;(other)&lt;br /&gt;    regex = /^[\d]+/&lt;br /&gt;    if self.title =~ regex&lt;br /&gt;      our_num = Regexp.last_match[0].to_i&lt;br /&gt;      if other.title =~ regex&lt;br /&gt;        other_num = Regexp.last_match[0].to_i&lt;br /&gt;        return our_num &lt;=&gt; other_num&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;    self.title &lt;=&gt; other.title&lt;br /&gt;  end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 23 Sep 2006 19:15:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2705</guid>
      <author>aptiva (Fj&#195;&#182;lnir &#195;?sgeirsson)</author>
    </item>
  </channel>
</rss>
