<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>Ernesto Herrera Salinas</title>
	<description>La Importancia de Llamarse Ernesto</description>
	<link>http://blog.ernestohs.com</link>
	<managingEditor>ernestohs@gmail.com (Ernesto Herrera Salinas)</managingEditor>
	<copyright>2009, Ernesto Herrera Salinas</copyright>
	<pubDate>Wed, 16 Jun 2010 12:04:54 -0400</pubDate>
	<generator>JAWS 0.8.9</generator>
	<atom:link href="http://blog.ernestohs.com/index.php/Blog/RSS" rel="self" type="application/rss+xml" />
	<item>
		<category>C#</category>
		<category>Español</category>
		<category>JavaScript</category>
		<category>Twitter</category>
		<category>ASP.NET</category>
		<title><![CDATA[ Un nano cliente de twitter hecho en 30 minutos desde cero en ASP.NET ]]></title>
		<description><![CDATA[ <p align="justify">Un día como cualquier otro, habla por el mensajero de la oficina con mi <a href="http://es.wikipedia.org/wiki/Sensei">Sensei</a> y nos pusimos a platicar sobe una entrevista que había hecho a un aspirante a developer donde le pedía que hiciera un programa sencillo consumiendo el <a href="http://apiwiki.twitter.com/">API de twitter</a> (Mostrar el Time Line y poder publicar el estatus) y me preguntaba si 1 hora de tiempo era suficiente, hice un "calculo" mental y se me hizo suficiente tiempo para completar la tarea, sin embargo me pregunte si yo podría hacerlo en menos tiempo (solo por pura diversión), puse el cronometro (ya con el IDE abierto y listo) y <strong><a href="http://www.coderun.com/ide/?w=l3Xj5Qg8ykCV1UUFm0gDGA">este fue el resultado</a></strong> después de 30 minutos (momento en el cual consideré que la tarea estaba cumplida).</p>
<center><img src="http://img295.imageshack.us/img295/6707/nanotwitter.png" /></center><br />
<h2>Paso a Paso</h2>
<br/><br />
<h3>#1 Autentificación</h3>
<p align="justify">El primer paso fue entonces hacer una autentificación del usuario, para lo cual ASP.NET tiene un control.<br/><center><img src="http://aspnet.4guysfromrolla.com/images/login1.gif" /></center></p>
<h3>#2 Time Line de Twitter</h3>
<p align="justify">El problema suena complicado pero el API de Twitter es muy amigable y ASP.NET tiene un control que se alimenta con XML, entonces solo tuve que conectar estos dos puntos.</p>
<h3>#3 Publicar status</h3>
<p align="justify">Habría ahorrado mucho tiempo usar <a href="http://linqtotwitter.codeplex.com/">LinQ2Twitter</a> pero olvide descargarlo y el tiempo no detenía su marcha así que de la forma más rupestre hice un <code>HttpRequest</code> para hacer update del estatus.</p>
<div class="code"><div class="c c" style="font-family:monospace;">
public <span style="color: #993333;">static</span> bool PostTweet<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span> username<span style="color: #339933;">,</span> <span style="color: #993333;">string</span> password<span style="color: #339933;">,</span> <span style="color: #993333;">string</span> tweet<span style="color: #009900;">&#41;</span><br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#123;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; try<br />
&#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #009900;">&#123;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #666666; font-style: italic;">// encode the username/password</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #993333;">string</span> user <span style="color: #339933;">=</span> Convert.<span style="color: #202020;">ToBase64String</span><span style="color: #009900;">&#40;</span>System.<span style="color: #202020;">Text</span>.<span style="color: #202020;">Encoding</span>.<span style="color: #202020;">UTF8</span>.<span style="color: #202020;">GetBytes</span><span style="color: #009900;">&#40;</span>username <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;:&quot;</span> <span style="color: #339933;">+</span> password<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #666666; font-style: italic;">// determine what we want to upload as a status</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; byte<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> bytes <span style="color: #339933;">=</span> System.<span style="color: #202020;">Text</span>.<span style="color: #202020;">Encoding</span>.<span style="color: #202020;">ASCII</span>.<span style="color: #202020;">GetBytes</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;status=&quot;</span> <span style="color: #339933;">+</span> tweet<span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #666666; font-style: italic;">// connect with the update page</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; HttpWebRequest request <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>HttpWebRequest<span style="color: #009900;">&#41;</span>WebRequest.<span style="color: #202020;">Create</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;http://twitter.com/statuses/update.xml&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #666666; font-style: italic;">// set the method to POST</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; request.<span style="color: #202020;">Method</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;POST&quot;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; request.<span style="color: #202020;">ServicePoint</span>.<span style="color: #202020;">Expect100Continue</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #666666; font-style: italic;">// set the authorisation levels</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; request.<span style="color: #202020;">Headers</span>.<span style="color: #202020;">Add</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Authorization&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Basic &quot;</span> <span style="color: #339933;">+</span> user<span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; request.<span style="color: #202020;">ContentType</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;application/x-www-form-urlencoded&quot;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #666666; font-style: italic;">// set the length of the content</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; request.<span style="color: #202020;">ContentLength</span> <span style="color: #339933;">=</span> bytes.<span style="color: #202020;">Length</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #666666; font-style: italic;">// set up the stream</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Stream reqStream <span style="color: #339933;">=</span> request.<span style="color: #202020;">GetRequestStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #666666; font-style: italic;">// write to the stream</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; reqStream.<span style="color: #202020;">Write</span><span style="color: #009900;">&#40;</span>bytes<span style="color: #339933;">,</span> <span style="color:#800080;">0</span><span style="color: #339933;">,</span> bytes.<span style="color: #202020;">Length</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #666666; font-style: italic;">// close the stream</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; reqStream.<span style="color: #202020;">Close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #009900;">&#125;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; catch <span style="color: #009900;">&#40;</span>Exception ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>; <span style="color: #009900;">&#125;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;<br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#125;</span><br />
&#160;</div></div>
<h3>#4 140 caracteres o menos</h3>
<p align="justify">Una de las características más conocidas de Twitter es la restricción de los 140 caracteres (o menos), la página de twitter tiene un contador de caracteres que debía incluir en mi programa, así tuve que agregar un par de funciones JavaScript para poder emular esta característica de la página original de twitter</p>
<div class="code"><div class="javascript javascript" style="font-family:monospace;">
<span style="color: #003366; font-weight: bold;">function</span> CountChars<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#123;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;lblCount&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">140</span> <span style="color: #339933;">-</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;% = status.ClientID %&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span>.<span style="color: #660066;">length</span>;<br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#125;</span><br />
&#160;</div></div>
<h3>#5 Talacha</h3>
<p align="justify">El resto fue solo talacha como decimos coloquialmente, todo el proceso fue muy rápido e indoloro, al presionar F5 probé el programa y todo salio bien (Al menos este programa no iría a las garras de QA).</p>
<h2>Ahí está el código...</h2>
<p align="justify">Si estas interesado en agregarle algo al proyecto, puedes hacerlo en Code Run (el <a href="http://www.coderun.com/ide/?w=l3Xj5Qg8ykCV1UUFm0gDGA">link ya lo puse al principio</a>) y/o mandarme tus comentarios.</p> ]]></description>
		<link>http://blog.ernestohs.com/index.php/blog/show/Un-nano-cliente-de-twitter-hecho-30-minutos-desde-cero-en-ASP.NET.html</link>
		<author>ernestohs@gmail.com (Ernesto Herrera Salinas)</author>
		<guid>http://blog.ernestohs.com/index.php/blog/show/Un-nano-cliente-de-twitter-hecho-30-minutos-desde-cero-en-ASP.NET.html</guid>
		<pubDate>Wed, 16 Jun 2010 01:40:11 -0400</pubDate>
	</item>
	<item>
		<category>C#</category>
		<category>Español</category>
		<category>Windows</category>
		<title><![CDATA[ Divertimento Programático - Invertir Texto ]]></title>
		<description><![CDATA[ <p align="justify">Cuando era estudiante, alguna vez nos pidieron hacer un programa (Java) que invirtiera el texto que se había escrito en la terminal, este problema que podría resolverlo hasta un mono drogado no despertó ningún interés, sin embargo y para no aburrirme decidí hacer un pequeño cambio de perspectiva. El programa se perdió junto con otras muchas cosas durante los años, pero aquí lo reproduzco (C#/Windows Forms).</p>
<h3>El Código</h3>
<div class="code"><div class="c c" style="font-family:monospace;">
public class StringReflection <br />
&#160; &#160; <span style="color: #009900;">&#123;</span><br />
&#160; &#160; &#160; &#160; private <span style="color: #993333;">string</span> InvertedABC <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot; `˙zʎxʍʌnʇsɹʞdouɯlʞɾıɥƃɟǝpɔqɐ&quot;</span>;<br />
&#160; &#160; &#160; &#160; private <span style="color: #993333;">string</span> StraightABC <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;abcdefghijklmnopqrstuvwxyz., &quot;</span>;<br />
&#160; &#160; &#160; &#160; public <span style="color: #993333;">string</span> Text;<br />
&#160; &#160; &#160; &#160; public StringReflection<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span> text<span style="color: #009900;">&#41;</span><br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#123;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; this.<span style="color: #202020;">Text</span> <span style="color: #339933;">=</span> text.<span style="color: #202020;">ToLower</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#125;</span><br />
&#160; &#160; &#160; &#160; public <span style="color: #993333;">string</span> Backwards<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#123;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; StringBuilder sb <span style="color: #339933;">=</span> new StringBuilder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #993333;">char</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> ɔqɐ <span style="color: #339933;">=</span> InvertedABC.<span style="color: #202020;">ToCharArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; Array.<span style="color: #202020;">Reverse</span><span style="color: #009900;">&#40;</span>ɔqɐ<span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; foreach <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> c in Text<span style="color: #009900;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #009900;">&#123;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; try<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #009900;">&#123;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; sb.<span style="color: #202020;">Append</span><span style="color: #009900;">&#40;</span>ɔqɐ<span style="color: #009900;">&#91;</span>StraightABC.<span style="color: #202020;">IndexOf</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #808080; font-style: italic;">/*Ignore the missed chars in the subset*/</span> <span style="color: #009900;">&#125;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #009900;">&#125;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #993333;">char</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> ʇxǝʇ <span style="color: #339933;">=</span> sb.<span style="color: #202020;">ToString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #202020;">ToCharArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; Array.<span style="color: #202020;">Reverse</span><span style="color: #009900;">&#40;</span>ʇxǝʇ<span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">return</span> new <span style="color: #993333;">String</span><span style="color: #009900;">&#40;</span>ʇxǝʇ<span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#125;</span><br />
&#160; &#160; <span style="color: #009900;">&#125;</span><br />
&#160;</div></div>
<BR/><br />
<img src="http://img707.imageshack.us/img707/7876/invertasyouwrite.png" /><br />
<BR/><br />
<p align="justify">Si quieren ver el proyecto lo pueden hacer <a title="Code Run" href="http://www.coderun.com/ide/?w=OqalOyMYN0ialeUE6MBrrQ">aquí</a> o pueden descargarlo a continuación:</p>
<iframe title ="Preview" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="width:98px;height:115px;padding:0;background-color:#fcfcfc;" src="http://cid-da0e21eab9e86ac2.office.live.com/embedicon.aspx/.Public/InvertAsYouWrite.zip"></iframe> ]]></description>
		<link>http://blog.ernestohs.com/index.php/blog/show/exp001.html</link>
		<author>ernestohs@gmail.com (Ernesto Herrera Salinas)</author>
		<guid>http://blog.ernestohs.com/index.php/blog/show/exp001.html</guid>
		<pubDate>Sun, 13 Jun 2010 12:13:07 -0400</pubDate>
	</item>
	<item>
		<category>Español</category>
		<category>Visual Basic .NET</category>
		<category>Twitter</category>
		<title><![CDATA[ Quitter un cliente ligero y discreto de Twitter ]]></title>
		<description><![CDATA[ <p align="justify"><a href="http://quitter.codeplex.com">Quitter</a> es un cliente ligero de twitter, además es muy discreto para aquellos entornos en los cuales no te dejan tener el "Twitter" abierto en el navegador. Encontré este cliente de pura casualidad y sin estar buscándolo, cuando lo baje me dio algo de lata configurar lo pero luego de configurado funciona de maravilla.</p>
<h3>Lo malo</h3>
El programa no te deja escribir acentos o Ñ's peeeeeero tengo un parche de 3 centavos para el código fuente que agrega esta pequeña funcionalidad y claro que si aquí está el parche para que se lo apliquen al código y puedan ser felices y comer perdices.<br />
<center><br />
<h4>El parche</h4>
<iframe title ="Preview" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="width:98px;height:115px;padding:0;background-color:#fcfcfc;" src="http://cid-da0e21eab9e86ac2.skydrive.live.com/embedicon.aspx/.Public/spanishChars.patch"></iframe><br />
</center><br />
<h3>El Código Fuente</h3>
Este proyecto esta muy bien diseñado y prueba de esto es que copiando el Main del código todo esta claro como el agua:<br />
<div class="code"><div class="vb vb" style="font-family:monospace;">
<span style="color: #b1b100;">Sub</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; Initialize<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; <span style="color: #b1b100;">Dim</span> QuitSelected <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Boolean</span> = <span style="color: #b1b100;">False</span><br />
&#160; &#160; &#160; &#160; <span style="color: #b1b100;">Do</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; WriteLine<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">If</span> _CurrentUser.<span style="color: #66cc66;">ScreenName</span> &lt;&gt; <span style="color: #b1b100;">String</span>.<span style="color: #66cc66;">Empty</span> <span style="color: #b1b100;">Then</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; WriteLine<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">String</span>.<span style="color: #b1b100;">Format</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;[{0} ({1})]&quot;</span>, _CurrentUser.<span style="color: #66cc66;">ScreenName</span>, _HitsRemaining<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span>MAIN_PROMPT<span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Dim</span> Choice <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span> = ReadKey<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;acdfhlpqrstu?x&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; Select <span style="color: #b1b100;">Case</span> Choice<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Case</span> <span style="color: #b1b100;">String</span>.<span style="color: #66cc66;">Empty</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Read &quot;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Read<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Case</span> <span style="color: #ff0000;">&quot;A&quot;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; WriteLine<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;About Quitter&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; About<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Case</span> <span style="color: #ff0000;">&quot;C&quot;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; WriteLine<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Configuration&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; ConfigureMenu<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Case</span> <span style="color: #ff0000;">&quot;D&quot;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Write</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Direct messages &quot;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; DirectMessageMenu<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Case</span> <span style="color: #ff0000;">&quot;F&quot;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; WriteLine<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Follow user&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; FollowUser<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Case</span> <span style="color: #ff0000;">&quot;L&quot;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; WriteLine<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Open link&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; OpenLink<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Case</span> <span style="color: #ff0000;">&quot;P&quot;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; WriteLine<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Post&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; PostUpdate<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Case</span> <span style="color: #ff0000;">&quot;Q&quot;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; WriteLine<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Quit&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">If</span> ReadYesNo<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Are you sure? (Y/N):&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">Then</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; QuitSelected = <span style="color: #b1b100;">True</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Case</span> <span style="color: #ff0000;">&quot;R&quot;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; WriteLine<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Reply&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Reply<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Case</span> <span style="color: #ff0000;">&quot;S&quot;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; WriteLine<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Search&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Search<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Case</span> <span style="color: #ff0000;">&quot;T&quot;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; WriteLine<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Re-tweet&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; ReTweet<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Case</span> <span style="color: #ff0000;">&quot;U&quot;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; WriteLine<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Unfollow user&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; UnFollowUser<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">Case</span> <span style="color: #ff0000;">&quot;?&quot;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; WriteLine<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Help&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; ShowHelp<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #b1b100;">End</span> Select<br />
&#160; &#160; &#160; &#160; <span style="color: #b1b100;">Loop</span> Until QuitSelected<br />
&#160; &#160; <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span><br />
&#160;</div></div> ]]></description>
		<link>http://blog.ernestohs.com/index.php/blog/show/Quitter-un-cliente-ligero-y-discreto-de-Twitter.html</link>
		<author>ernestohs@gmail.com (Ernesto Herrera Salinas)</author>
		<guid>http://blog.ernestohs.com/index.php/blog/show/Quitter-un-cliente-ligero-y-discreto-de-Twitter.html</guid>
		<pubDate>Fri, 01 Jan 2010 00:57:51 -0500</pubDate>
	</item>
	<item>
		<category>General</category>
		<category>C#</category>
		<category>Java</category>
		<category>PowerShell</category>
		<category>C++</category>
		<category>LinQ</category>
		<category>Español</category>
		<category>Windows</category>
		<title><![CDATA[ Ordenamiento De Cadenas Por Longitud ]]></title>
		<description><![CDATA[ <blockquote align="justify">Tienes una lista de cadenas y quieres ordenarlas según su longitud, de la más corta a la más larga. Esta misma solución se puede aplicar cambiando el criterio: alfabeticamente, mayor número de vocales, etc. Aquí expongo diferentes implementaciones de la misma estrategia en Java, C#, C++, PowerShell y C# con LinQ.</blockquote>
<h2>Introducción</h2>
<p align="justify">Como buen programador una de las cosas que más odio es hacer algo más de una vez, y lo que odio aún más es tener que explicar lo mismo más de una vez a una o varias personas, así que decidí publicar en mi Blog las respuestas a las preguntas más solicitadas por todos aquellos que me acosan en el correo electrónico, Messenger, celular, etc. (No se hagan ustedes saben quienes son).</p>
<p align="justify">El siguiente problema es un clásico, desde estudiantes de primer semestre hasta administradores de sistemas me han preguntado lo mismo (o alguna variante). Inclusive un estudiante me comento que tenia ya un mes intentando resolver este problema (de que los hay, los hay).</p>
<h2>Problema</h2>
<p align="justify">Tenemos una lista de cadenas y queremos ordenarlas de menor longitud a mayor longitud. Veamos pues un ejemplo:</p>
<table align="center" style="text-align: left; width: 238px;border:1px" border="1">
  <tbody>
    <tr align="center">
      <td style="width: 110px;background-color:black;color:white;">Entrada</td>
      <td style="width: 110px;background-color:black;color:white;">Salida</td>
    </tr>
    <tr>
      <td style="width: 110px;">Aerocrofobia</td>
      <td style="width: 110px;">No</td>
    </tr>
    <tr>
      <td style="width: 110px;">Haba</td>
      <td style="width: 110px;">Caf&eacute;</td>
    </tr>
    <tr>
      <td style="width: 110px;">No</td>
      <td style="width: 110px;">Haba</td>
    </tr>
    <tr>
      <td style="width: 110px;">Acluofobia</td>
      <td style="width: 110px;">Persa</td>
    </tr>
    <tr>
      <td style="width: 110px;">Bienvenido</td>
      <td style="width: 110px;">Litros</td>
    </tr>
    <tr>
      <td style="width: 110px;">Amaxofobia</td>
      <td style="width: 110px;">Palabra</td>
    </tr>
    <tr>
      <td style="width: 110px;">Palabra</td>
      <td style="width: 110px;">Iniciar</td>
    </tr>
    <tr>
      <td style="width: 110px;">Reflexolog&iacute;a</td>
      <td style="width: 110px;">Platano</td>
    </tr>
    <tr>
      <td style="width: 110px;">Atazagorafobia</td>
      <td style="width: 110px;">Gasolina</td>
    </tr>
    <tr>
      <td style="width: 110px;">Persa</td>
      <td style="width: 110px;">Aut&oacute;mata</td>
    </tr>
    <tr>
      <td style="width: 110px;">Aut&oacute;mata</td>
      <td style="width: 110px;">Amaxofobia</td>
    </tr>
    <tr>
      <td style="width: 110px;">Iniciar</td>
      <td style="width: 110px;">Acluofobia</td>
    </tr>
    <tr>
      <td style="width: 110px;">Allodoxafobia</td>
      <td style="width: 110px;">Bienvenido</td>
    </tr>
    <tr>
      <td style="width: 110px;">Litros</td>
      <td style="width: 110px;">Importante</td>
    </tr>
    <tr>
      <td style="width: 110px;">Apotenmofobia</td>
      <td style="width: 110px;">Aracnofobia</td>
    </tr>
    <tr>
      <td style="width: 110px;">Gasolina</td>
      <td style="width: 110px;">Reflexolog&iacute;a</td>
    </tr>
    <tr>
      <td style="width: 110px;">Platano</td>
      <td style="width: 110px;">Aerocrofobia</td>
    </tr>
    <tr>
      <td style="width: 110px;">Caf&eacute;</td>
      <td style="width: 110px;">Allodaxofobia</td>
    </tr>
    <tr>
      <td style="width: 110px;">Importante</td>
      <td style="width: 110px;">Apotenmofobia</td>
    </tr>
    <tr>
      <td style="width: 110px;">Aracnofobia</td>
      <td style="width: 110px;">Atazagorafobia</td>
    </tr>
  </tbody>
</table>
<h2>Solución</h2>
<p align="justify">A continuación expondré la misma solución en diferentes lenguajes, la solución siempre es la misma, solo se necesita establecer el criterio de ordenamiento en la función o método de ordenamiento.</p>
<h3>Versión Java™</h3>
<p align="justify">Este va primero por que nada arruina más mi día que tener que hablar de este P<span style="background-color:black;color:white;"><abr title="Odio este maldito lenguaje de porqueria">CENSURADO</abr></span>e lenguaje. Aquí pues el código:</p>
<p align="right">PorLongitud.java</p>
<div class="code"><div class="java java" style="font-family:monospace;">
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Comparator</span>;<br />
<span style="color: #000000; font-weight: bold;">class</span> PorLongitud <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Comparator</span> <span style="color: #009900;">&#123;</span><br />
&#160; &#160; &#160; &#160; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> compare<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> o1, <span style="color: #003399;">Object</span> o2<span style="color: #009900;">&#41;</span> <br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#123;</span> <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #003399;">String</span> a <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span> o1; <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #003399;">String</span> b <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span> o2; <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span> a.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> b.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">?-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">1</span>; <br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#125;</span><br />
&#160; &#160; &#160; &#160; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> equals<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> o<span style="color: #009900;">&#41;</span> <br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#123;</span> <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span> <span style="color: #339933;">==</span> o; <br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#125;</span> <br />
&#160; &#160; &#160; &#160; <br />
<span style="color: #009900;">&#125;</span><br />
&#160;</div></div>
<p align="right">Programa.java</p>
<div class="code"><div class="java java" style="font-family:monospace;">
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span>;<br />
<span style="color: #000000; font-weight: bold;">class</span> Programa <span style="color: #009900;">&#123;</span><br />
&#160; &#160; &#160; &#160; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span><br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#123;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #003399;">ArrayList</span> lista <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Aeroacrofobia&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Haba&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Amaxofobia&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Bienvenido&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Palabra&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Reflexología&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Persa&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Autómata&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Iniciar&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Allodoxafobia&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Litros&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Gasolina&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Platano&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Café&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Importante&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Aracnofobia&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> o <span style="color: #339933;">:</span> lista<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> o <span style="color: #009900;">&#41;</span>; <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #009900;">&#125;</span> <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #003399;">Collections</span>.<span style="color: #006633;">sort</span><span style="color: #009900;">&#40;</span>lista, <span style="color: #000000; font-weight: bold;">new</span> PorLongitud<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> o <span style="color: #339933;">:</span> lista<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> o <span style="color: #009900;">&#41;</span>; <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #009900;">&#125;</span> <br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
&#160;</div></div>
<h3>Versión C# <sub>(I love this language)</sub></h3>
<p align="justify">Saber <strong>delegar</strong> es la característica más importante de un buen <strike>líder</strike> programador:</p>
<div class="code"><div class="c c" style="font-family:monospace;">
class Program <span style="color: #009900;">&#123;</span> <br />
&#160; &#160; &#160; &#160; <span style="color: #993333;">static</span> <span style="color: #993333;">void</span> Main<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; List<span style="color: #339933;">&lt;</span>string<span style="color: #339933;">&gt;</span> lista <span style="color: #339933;">=</span> new List<span style="color: #339933;">&lt;</span>string<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #ff0000;">&quot;Aeroacrofobia&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Haba&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;No&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Amaxofobia&quot;</span><span style="color: #339933;">,</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #ff0000;">&quot;Bienvenido&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Palabra&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Reflexología&quot;</span><span style="color: #339933;">,</span> <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #ff0000;">&quot;Persa&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Autómata&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Iniciar&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Allodoxafobia&quot;</span><span style="color: #339933;">,</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #ff0000;">&quot;Litros&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Gasolina&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Platano&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Café&quot;</span><span style="color: #339933;">,</span> <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #ff0000;">&quot;Importante&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Aracnofobia&quot;</span> <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #009900;">&#125;</span>; <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #202020;">ForEach</span><span style="color: #009900;">&#40;</span>delegate<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span> item<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> System.<span style="color: #202020;">Console</span>.<span style="color: #202020;">WriteLine</span><span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #202020;">Sort</span><span style="color: #009900;">&#40;</span>delegate<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span> a<span style="color: #339933;">,</span> <span style="color: #993333;">string</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> a.<span style="color: #202020;">Length</span>.<span style="color: #202020;">CompareTo</span><span style="color: #009900;">&#40;</span>b.<span style="color: #202020;">Length</span><span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #202020;">ForEach</span><span style="color: #009900;">&#40;</span>delegate<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span> item<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> System.<span style="color: #202020;">Console</span>.<span style="color: #202020;">WriteLine</span><span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>; <br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
&#160;</div></div>
<p align="justify">Puedes descargar el código para Visual Studio 2008 <a href="http://cid-50f6b77bd41cf996.skydrive.live.com/self.aspx/Mini-Desarrollos/OrdenamientoPorLongitud/Ordenamiento%20Por%20Longitud%20CSharp.zip">aquí</a>:</p>
<iframe align="center" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="width:240px;height:66px;margin:3px;padding:0;border:1px solid #dde5e9;background-color:#ffffff;" src="http://cid-50f6b77bd41cf996.skydrive.live.com/embedrowdetail.aspx/Mini-Desarrollos/OrdenamientoPorLongitud/Ordenamiento%20Por%20Longitud%20CSharp.zip"></iframe><br />
<p align="justify">Para aquellos interesados en LinQ al final de este bloque presento la solución usando solamente LinQ(Para que vean que bonito se programa en C#).</p>
<h3>Versión C++</h3>
<div class="code"><div class="c c" style="font-family:monospace;">
<span style="color: #339933;">#include &lt;iostream&gt;</span><br />
<span style="color: #339933;">#include &lt;list&gt;</span><br />
<span style="color: #339933;">#include &lt;string&gt;</span><br />
<span style="color: #339933;">#include &lt;algorithm&gt;</span><br />
using namespace std;<br />
bool PorLogitud<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span> a<span style="color: #339933;">,</span> <span style="color: #993333;">string</span> b<span style="color: #009900;">&#41;</span> <br />
<span style="color: #009900;">&#123;</span> <br />
&#160; &#160; &#160; &#160; <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span> a.<span style="color: #202020;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> b.<span style="color: #202020;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>; <br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />
<span style="color: #009900;">&#123;</span><br />
&#160; &#160; &#160; &#160; list<span style="color: #339933;">&lt;</span>string<span style="color: #339933;">&gt;</span> ListaCadenas;<br />
&#160; &#160; &#160; &#160; list<span style="color: #339933;">&lt;</span>string<span style="color: #339933;">&gt;::</span><span style="color: #202020;">iterator</span> it;<br />
&#160; &#160; &#160; &#160; <br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Aeroacrofobia&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Haba&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Amaxofobia&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Bienvenido&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Palabra&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Reflexología&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Persa&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Autómata&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Iniciar&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Allodoxafobia&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Litros&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Gasolina&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Platano&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Café&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Importante&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">push_back</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Aracnofobia&quot;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; ListaCadenas.<span style="color: #202020;">sort</span><span style="color: #009900;">&#40;</span>PorLogitud<span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; <br />
&#160; &#160; &#160; &#160; <span style="color: #000066;">cout</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #ff0000;">&quot;Mi Lista:&quot;</span> <span style="color: #339933;">&lt;&lt;</span> endl;<br />
&#160; &#160; &#160; &#160; <br />
&#160; &#160; &#160; &#160; <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>it<span style="color: #339933;">=</span>ListaCadenas.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; it<span style="color: #339933;">!=</span>ListaCadenas.<span style="color: #202020;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #339933;">++</span>it<span style="color: #009900;">&#41;</span> <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #000066;">cout</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #339933;">*</span>it <span style="color: #339933;">&lt;&lt;</span> endl; <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <br />
&#160; &#160; &#160; &#160; <span style="color: #b1b100;">return</span> <span style="color:#800080;">0</span>; <br />
<span style="color: #009900;">&#125;</span><br />
&#160;</div></div>
<h3>Versión PowerShell</h3>
<div class="terminal">
PS > Get-content -Path cadenas.txt | Sort-Object -Property Length
</div>
<h3>Versión C# Con LINQ (.NET 3.5)</h3>
<p align="justify">Haciendo uso de esta nueva característica este problema it’s a fuking peace of cake. Veamos el código:</p>
<div class="code"><div class="c c" style="font-family:monospace;">
public <span style="color: #993333;">static</span> List<span style="color: #339933;">&lt;</span>string<span style="color: #339933;">&gt;</span> OrdenarPorLongitud<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>string<span style="color: #339933;">&gt;</span> lista<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <br />
&#160; &#160; &#160; &#160; var ordenado <span style="color: #339933;">=</span> from cadena in lista orderby cadena.<span style="color: #202020;">Length</span> ascending select cadena; <br />
&#160; &#160; &#160; &#160; <span style="color: #b1b100;">return</span> ordenado.<span style="color: #202020;">ToList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <br />
<span style="color: #009900;">&#125;</span><br />
&#160;</div></div>
<p align="justify">¿La quieren aún más fácil?, pues ahí les va con expresiones Lamda:</p>
<div class="code"><div class="c c" style="font-family:monospace;">
class Program <span style="color: #009900;">&#123;</span><br />
&#160; &#160; &#160; &#160; <span style="color: #993333;">static</span> <span style="color: #993333;">void</span> Main<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <br />
&#160; &#160; &#160; &#160; <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; List<span style="color: #339933;">&lt;</span>string<span style="color: #339933;">&gt;</span> lista <span style="color: #339933;">=</span> new List<span style="color: #339933;">&lt;</span>string<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #ff0000;">&quot;Aeroacrofobia&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Haba&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;No&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Amaxofobia&quot;</span><span style="color: #339933;">,</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #ff0000;">&quot;Bienvenido&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Palabra&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Reflexología&quot;</span><span style="color: #339933;">,</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #ff0000;">&quot;Persa&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Autómata&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Iniciar&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Allodoxafobia&quot;</span><span style="color: #339933;">,</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #ff0000;">&quot;Litros&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Gasolina&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Platano&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Café&quot;</span><span style="color: #339933;">,</span><br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #ff0000;">&quot;Importante&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Aracnofobia&quot;</span> <span style="color: #009900;">&#125;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #202020;">ForEach</span><span style="color: #009900;">&#40;</span>delegate<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span> item<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> System.<span style="color: #202020;">Console</span>.<span style="color: #202020;">WriteLine</span><span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #202020;">Sort</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>b<span style="color: #009900;">&#41;</span> <span style="color: #339933;">=&gt;</span> a.<span style="color: #202020;">Length</span>.<span style="color: #202020;">CompareTo</span><span style="color: #009900;">&#40;</span>b.<span style="color: #202020;">Length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>;<br />
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; lista.<span style="color: #202020;">ForEach</span><span style="color: #009900;">&#40;</span>delegate<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span> item<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> System.<span style="color: #202020;">Console</span>.<span style="color: #202020;">WriteLine</span><span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>; <br />
&#160; &#160; &#160; &#160; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
&#160;</div></div>
<h3>Conclusión</h3>
<p align="justify">No hay razón para reinventar la rueda, el programador más listo es aquel que se duerme más temprano.</p> ]]></description>
		<link>http://blog.ernestohs.com/index.php/blog/show/Ordenamiento-De-Cadenas-Por-Longitud.html</link>
		<author>ernestohs@gmail.com (Ernesto Herrera Salinas)</author>
		<guid>http://blog.ernestohs.com/index.php/blog/show/Ordenamiento-De-Cadenas-Por-Longitud.html</guid>
		<pubDate>Sun, 26 Jul 2009 19:56:46 -0400</pubDate>
	</item>
</channel>
</rss>
