<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Remove Duplicate Chars from a String</title>
	<atom:link href="http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/</link>
	<description>flex developers web corner</description>
	<lastBuildDate>Sun, 14 Mar 2010 14:43:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Dustin Ramirez</title>
		<link>http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/comment-page-1/#comment-1735</link>
		<dc:creator>Dustin Ramirez</dc:creator>
		<pubDate>Wed, 28 Oct 2009 02:52:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/#comment-1735</guid>
		<description>PERL SCRIPT:
&lt;pre lang=&quot;perl&quot;&gt;$str = &#039;aabbccaaaaddaaeeffbb&#039;;
while ($str =~ s/(.)(.*?)\1+/$1$2/g) {}
print $str;&lt;/pre&gt;

OUTPUT: 
abcdef</description>
		<content:encoded><![CDATA[<p>PERL SCRIPT:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #0000ff;">$str</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'aabbccaaaaddaaeeffbb'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$str</span> <span style="color: #339933;">=~</span> <span style="color: #000066;">s</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">.</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">.*?</span><span style="color: #009900;">&#41;</span>\<span style="color: #cc66cc;">1</span><span style="color: #339933;">+/</span><span style="color: #0000ff;">$1</span><span style="color: #0000ff;">$2</span><span style="color: #339933;">/</span>g<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000066;">print</span> <span style="color: #0000ff;">$str</span><span style="color: #339933;">;</span></pre></div></div>

<p>OUTPUT:<br />
abcdef</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrei Ionescu</title>
		<link>http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/comment-page-1/#comment-250</link>
		<dc:creator>Andrei Ionescu</dc:creator>
		<pubDate>Tue, 03 Jun 2008 10:50:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/#comment-250</guid>
		<description>Thanks Michael for your idea. It sounds good and I&#039;ll benchmark it. As far as I know in ActionScript is no direct method or function that will inverse/transpose an array but is worth trying to implement the loop as you explained in your comment. Thanks!</description>
		<content:encoded><![CDATA[<p>Thanks Michael for your idea. It sounds good and I&#8217;ll benchmark it. As far as I know in ActionScript is no direct method or function that will inverse/transpose an array but is worth trying to implement the loop as you explained in your comment. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Ekoka</title>
		<link>http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/comment-page-1/#comment-249</link>
		<dc:creator>Michael Ekoka</dc:creator>
		<pubDate>Tue, 03 Jun 2008 10:38:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/#comment-249</guid>
		<description>I&#039;m not very familiar with actionscript, I stumbled upon your site while looking for a reminder on the regex syntax for look-behind in vim and was just a bit fascinated by this problem. I&#039;m just curious, is there a way to transpose an AS array with a native function, so that the values become keys (like in a hash table / associative array)? I assume that in AS like in most other languages, array keys are unique. If it is possible maybe the language native constructs could do these operations faster :
1- split the string in an array
2- transpose the array (which should automatically eliminate duplicate keys).
3- gather all the keys and you have your unique values.

Based on the same concept, if you can&#039;t transpose the array, you could just do a single loop through it and assign its values as keys and values to another array:
(reminder i don&#039;t know AS, this code is based on what i&#039;ve seen above, try to decipher the logic)
&lt;code&gt;
var firstArray:Array = thestring.split(&#039;&#039;);
var secondArray:Array = new Array();
firstArray.forEach(
&#160;&#160;&#160;&#160;function (){
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;secondArray[item] = item;
&#160;&#160;&#160;&#160;}
);
&lt;/code&gt;

Reorder the second array after the operation, since it&#039;s shorter the reordering operation is more efficient.

There&#039;s no guarantee that the whole thing will be faster, if you have the time to benchmark it, maybe it&#039;s worth a shot. Off I go.</description>
		<content:encoded><![CDATA[<p>I&#8217;m not very familiar with actionscript, I stumbled upon your site while looking for a reminder on the regex syntax for look-behind in vim and was just a bit fascinated by this problem. I&#8217;m just curious, is there a way to transpose an AS array with a native function, so that the values become keys (like in a hash table / associative array)? I assume that in AS like in most other languages, array keys are unique. If it is possible maybe the language native constructs could do these operations faster :<br />
1- split the string in an array<br />
2- transpose the array (which should automatically eliminate duplicate keys).<br />
3- gather all the keys and you have your unique values.</p>
<p>Based on the same concept, if you can&#8217;t transpose the array, you could just do a single loop through it and assign its values as keys and values to another array:<br />
(reminder i don&#8217;t know AS, this code is based on what i&#8217;ve seen above, try to decipher the logic)<br />
<code><br />
var firstArray:Array = thestring.split('');<br />
var secondArray:Array = new Array();<br />
firstArray.forEach(<br />
&nbsp;&nbsp;&nbsp;&nbsp;function (){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;secondArray[item] = item;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
);<br />
</code></p>
<p>Reorder the second array after the operation, since it&#8217;s shorter the reordering operation is more efficient.</p>
<p>There&#8217;s no guarantee that the whole thing will be faster, if you have the time to benchmark it, maybe it&#8217;s worth a shot. Off I go.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrei Ionescu</title>
		<link>http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/comment-page-1/#comment-180</link>
		<dc:creator>Andrei Ionescu</dc:creator>
		<pubDate>Wed, 23 Apr 2008 15:16:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/#comment-180</guid>
		<description>A new post has arrived &lt;a href=&quot;http://www.flexer.info/2008/04/23/comparison-remove-duplicate-chars-from-a-string-via-array-and-regexp/&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;. Is a comparison between the methods to get a string with unique chars. Thanks TLP for sharing your solution.</description>
		<content:encoded><![CDATA[<p>A new post has arrived <a href="http://www.flexer.info/2008/04/23/comparison-remove-duplicate-chars-from-a-string-via-array-and-regexp/" rel="nofollow">here</a>. Is a comparison between the methods to get a string with unique chars. Thanks TLP for sharing your solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrei Ionescu</title>
		<link>http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/comment-page-1/#comment-179</link>
		<dc:creator>Andrei Ionescu</dc:creator>
		<pubDate>Wed, 23 Apr 2008 13:09:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/#comment-179</guid>
		<description>Thanks Dave! A really nice algorithm at the first view. The problem with it is that is not working properly. Try to use it with &quot;&lt;strong&gt;&lt;u&gt;aa&lt;/u&gt;bbcc&lt;u&gt;aaaa&lt;/u&gt;dd&lt;u&gt;aa&lt;/u&gt;eeff&lt;/strong&gt;&quot; which should be transformed to &quot;&lt;strong&gt;abcdef&lt;/strong&gt;&quot;. But is not doing what it should because when you do splice on the array you are looping the end condition of the loop changes because the length changes and also the position pointer inside the array changes. Everything is just getting messed up. Thanks for the idea and maybe you&#039;ll work out on this algorithm but not looping on and modifying the same array.</description>
		<content:encoded><![CDATA[<p>Thanks Dave! A really nice algorithm at the first view. The problem with it is that is not working properly. Try to use it with &#8220;<strong><u>aa</u>bbcc<u>aaaa</u>dd<u>aa</u>eeff</strong>&#8221; which should be transformed to &#8220;<strong>abcdef</strong>&#8220;. But is not doing what it should because when you do splice on the array you are looping the end condition of the loop changes because the length changes and also the position pointer inside the array changes. Everything is just getting messed up. Thanks for the idea and maybe you&#8217;ll work out on this algorithm but not looping on and modifying the same array.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: FLEX{er} &#187; Blog Archive &#187; Comparison: Remove Duplicate Chars from a String Via Array and RegExp</title>
		<link>http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/comment-page-1/#comment-178</link>
		<dc:creator>FLEX{er} &#187; Blog Archive &#187; Comparison: Remove Duplicate Chars from a String Via Array and RegExp</dc:creator>
		<pubDate>Wed, 23 Apr 2008 11:59:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/#comment-178</guid>
		<description>[...] In my previous article TLP has commented and created a better method. You can see his post here. [...]</description>
		<content:encoded><![CDATA[<div style="padding: 1em; background: #d3e1ef; /* border: dotted 1px #777777; */">
<p>[...] In my previous article TLP has commented and created a better method. You can see his post here. [...]</p>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/comment-page-1/#comment-177</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Wed, 23 Apr 2008 10:51:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/#comment-177</guid>
		<description>&lt;a href=&quot;http://jared.simplistika.com/actionscript-3-remove-duplicates-in-an-array/&quot; rel=&quot;nofollow&quot;&gt;This should help.&lt;/a&gt; 

Worked for me.</description>
		<content:encoded><![CDATA[<p><a target="_blank" href="http://jared.simplistika.com/actionscript-3-remove-duplicates-in-an-array/" rel="nofollow">This should help.</a> </p>
<p>Worked for me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TLP</title>
		<link>http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/comment-page-1/#comment-176</link>
		<dc:creator>TLP</dc:creator>
		<pubDate>Wed, 23 Apr 2008 03:50:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/#comment-176</guid>
		<description>Ah, terribly sorry about the misunderstanding. I really should read better before making a fool of myself.

Anyway, I came up with this little gem that&#039;s a play off my previous code.
&lt;code&gt;function removeDuplicates(string:String):String {
    return string.split(&#039;&#039;).sort().join(&#039;&#039;).replace(/(.)\1+/gi,&#039;$1&#039;);
}&lt;/code&gt;

Benchmark on 10,000 runs in AS3

Yours from the post above: 1.0310000000000024 seconds
Mine from this comment:  0.48499999999999943 seconds

Once again, apologies for the misunderstanding and hopefully I didn&#039;t mess it up again.</description>
		<content:encoded><![CDATA[<p>Ah, terribly sorry about the misunderstanding. I really should read better before making a fool of myself.</p>
<p>Anyway, I came up with this little gem that&#8217;s a play off my previous code.<br />
<code>function removeDuplicates(string:String):String {<br />
    return string.split('').sort().join('').replace(/(.)\1+/gi,'$1');<br />
}</code></p>
<p>Benchmark on 10,000 runs in AS3</p>
<p>Yours from the post above: 1.0310000000000024 seconds<br />
Mine from this comment:  0.48499999999999943 seconds</p>
<p>Once again, apologies for the misunderstanding and hopefully I didn&#8217;t mess it up again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrei Ionescu</title>
		<link>http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/comment-page-1/#comment-173</link>
		<dc:creator>Andrei Ionescu</dc:creator>
		<pubDate>Wed, 23 Apr 2008 00:45:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/#comment-173</guid>
		<description>TLP thanks but is &lt;b&gt;NOT&lt;/b&gt; what I needed. 

So what I needed is a string like &quot;&lt;b&gt;aabbccaaaaaddee&lt;/b&gt;&quot; to be transformed to &quot;&lt;b&gt;abcde&lt;/b&gt;&quot; (please note that there are two groups of &quot;&lt;b&gt;a&lt;/b&gt;&quot;s in the first string and only one &quot;&lt;b&gt;a&lt;/b&gt;&quot; in the resulting group).

Using &quot;&lt;b&gt;aabbccaaaaaddee&lt;/b&gt;&quot; in your regular expression will give us the result &quot;&lt;b&gt;&lt;u&gt;a&lt;/u&gt;bc&lt;u&gt;a&lt;/u&gt;de&lt;/b&gt;&quot; which is different from &quot;&lt;b&gt;&lt;u&gt;a&lt;/u&gt;bcde&lt;/b&gt;&quot; (note the underlined letters). I need unique chars in the resulting string.

I tried with regular expression but there is no easy way (one step).

Thanks also for benchmarks. Great job.</description>
		<content:encoded><![CDATA[<p>TLP thanks but is <b>NOT</b> what I needed. </p>
<p>So what I needed is a string like &#8220;<b>aabbccaaaaaddee</b>&#8221; to be transformed to &#8220;<b>abcde</b>&#8221; (please note that there are two groups of &#8220;<b>a</b>&#8220;s in the first string and only one &#8220;<b>a</b>&#8221; in the resulting group).</p>
<p>Using &#8220;<b>aabbccaaaaaddee</b>&#8221; in your regular expression will give us the result &#8220;<b><u>a</u>bc<u>a</u>de</b>&#8221; which is different from &#8220;<b><u>a</u>bcde</b>&#8221; (note the underlined letters). I need unique chars in the resulting string.</p>
<p>I tried with regular expression but there is no easy way (one step).</p>
<p>Thanks also for benchmarks. Great job.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TLP</title>
		<link>http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/comment-page-1/#comment-172</link>
		<dc:creator>TLP</dc:creator>
		<pubDate>Wed, 23 Apr 2008 00:32:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.flexer.info/2008/03/11/remove-duplicate-chars-from-a-string/#comment-172</guid>
		<description>Here&#039;s the same thing in AS3 (I&#039;m quite terrible at AS3, so I didn&#039;t think I&#039;d have any luck figuring it out)

&lt;code&gt;var myPattern:RegExp = /(.)\1+/gi;
var str:String = &quot;aaabbbcccddeeff&quot;;
trace(str.replace(myPattern, &#039;$1&#039;));&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Here&#8217;s the same thing in AS3 (I&#8217;m quite terrible at AS3, so I didn&#8217;t think I&#8217;d have any luck figuring it out)</p>
<p><code>var myPattern:RegExp = /(.)\1+/gi;<br />
var str:String = "aaabbbcccddeeff";<br />
trace(str.replace(myPattern, '$1'));</code></p>
]]></content:encoded>
	</item>
</channel>
</rss>
