Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's how computers look at the strings and compare them.</p> <p>If we look at the first characters of each word it'll help a little, because we know how the alphabet orders letters:</p> <pre><code>%w[hello my time here is long].map{ |s| s[0] }.sort # =&gt; ["h", "h", "i", "l", "m", "t"] </code></pre> <p>But that doesn't really help visualize it, so here's a look at each word's letters as a computer sees them:</p> <pre><code>%w[time tome].each do |w| puts w.chars.map(&amp;:ord).join(', ') end # &gt;&gt; 116, 105, 109, 101 # &gt;&gt; 116, 111, 109, 101 </code></pre> <p>Each letter has a value. Over the years there have been many different ways of ordering letters for a computer, which caused the character to value mapping to change. <a href="http://en.wikipedia.org/wiki/EBCDIC" rel="nofollow">EBCDIC</a> and <a href="http://en.wikipedia.org/wiki/ASCII" rel="nofollow">ASCII</a> have been the most popular but have different orders. We're usually dealing with ASCII, or a derivative, which is set by the OS.</p> <p>Look at how the characters in the words are represented by the values in the following output. It should make it easy to understand what the computer is doing then.</p> <pre><code>%w[he hello help holler hollow].sort.each do |w| puts '"%6s": %s' % [ w, w.chars.map(&amp;:ord).join(', ') ] end # &gt;&gt; " he": 104, 101 # &gt;&gt; " hello": 104, 101, 108, 108, 111 # &gt;&gt; " help": 104, 101, 108, 112 # &gt;&gt; "holler": 104, 111, 108, 108, 101, 114 # &gt;&gt; "hollow": 104, 111, 108, 108, 111, 119 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload