<?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/"
	>

<channel>
	<title>Flex Examples &#187; join()</title>
	<atom:link href="http://blog.flexexamples.com/tag/join/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Trimming strings using the Flex StringUtil class&#8217;s trimArrayElements() method</title>
		<link>http://blog.flexexamples.com/2007/09/07/trimming-strings-using-the-flex-stringutil-classs-trimarrayelements-method/</link>
		<comments>http://blog.flexexamples.com/2007/09/07/trimming-strings-using-the-flex-stringutil-classs-trimarrayelements-method/#comments</comments>
		<pubDate>Sat, 08 Sep 2007 06:01:09 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[StringUtil]]></category>
		<category><![CDATA[join()]]></category>
		<category><![CDATA[split()]]></category>
		<category><![CDATA[trimArrayElements()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/09/07/trimming-strings-using-the-flex-stringutil-classs-trimarrayelements-method/</guid>
		<description><![CDATA[<p>The following example shows how you can remove leading and trailing spaces from an Array using the Flex StringUtil class&#8217;s trimArrayElements() method.</p> <p>Similar to my earlier post, &#8220;<a href="http://blog.flexexamples.com/2007/09/07/trimming-strings-using-the-flex-stringutil-classs-trim-method/">Trimming strings using the Flex StringUtil class&#8217;s trim() method</a>&#8220;, the StringUtil class has another rediculously handy method, trimArrayElements().</p> <p>Essentially, this method allows you to trim leading and [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can remove leading and trailing spaces from an Array using the Flex StringUtil class&#8217;s <code>trimArrayElements()</code> method.</p>
<p>Similar to my earlier post, &#8220;<a href="http://blog.flexexamples.com/2007/09/07/trimming-strings-using-the-flex-stringutil-classs-trim-method/">Trimming strings using the Flex StringUtil class&#8217;s trim() method</a>&#8220;, the StringUtil class has another rediculously handy method, <code>trimArrayElements()</code>.</p>
<p>Essentially, this method allows you to trim leading and trailing whitespace from every element an array with one single method call, rather than having to resort to awkward loops and variable reassignments. The only real &#8220;gotcha&#8221; is that this method expects a string as a parameter and return value instead of an Array object.</p>
<p>Sayeth the docs:</p>
<blockquote><p>
<code>public static function trimArrayElements(value:String, delimiter:String):String {...}</code><br />
Removes all whitespace characters from the beginning and end of each element in an Array, where the Array is stored as a String.
</p></blockquote>
<p>Full code after the jump.</p>
<p><span id="more-160"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/StringUtil_trimArrayElements_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/09/07/trimming-strings-using-the-flex-stringutil-classs-trimarrayelements-method/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="horizontal"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init()"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.utils.StringUtil;

            private function init():void {
                var arrayStr:String = arrayToList(arr);
                arrayStr = StringUtil.trimArrayElements(arrayStr, ",");
                list2.dataProvider = listToArray(arrayStr);
            }

            private function listToArray(value:String, delimiter:String = ","):Array {
                return value.split(delimiter);
            }

            private function arrayToList(value:Array, delimiter:String = ","):String {
                return value.join(delimiter);
            }

            private function addSingleQuotes(item:Object):String {
                return "\'" + item.toString() + "\'";
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Array id="arr"&gt;
        &lt;mx:String&gt;       The &lt;/mx:String&gt;
        &lt;mx:String&gt; quick    &lt;/mx:String&gt;
        &lt;mx:String&gt;
            brown

        &lt;/mx:String&gt;
        &lt;mx:String&gt;    fox                &lt;/mx:String&gt;
    &lt;/mx:Array&gt;

    &lt;mx:List id="list1"
            dataProvider="{arr}"
            variableRowHeight="true"
            labelFunction="addSingleQuotes" /&gt;

    &lt;mx:List id="list2"
            variableRowHeight="true"
            labelFunction="addSingleQuotes" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/StringUtil_trimArrayElements_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/StringUtil_trimArrayElements_test/bin/main.html" width="100%" height="220"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Trimming strings using the Flex StringUtil class\&#039;s trimArrayElements() method on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/09/07/trimming-strings-using-the-flex-stringutil-classs-trimarrayelements-method/',contentID: 'post-160',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'join(),split(),trimArrayElements()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/09/07/trimming-strings-using-the-flex-stringutil-classs-trimarrayelements-method/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

