<?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; String</title>
	<atom:link href="http://blog.flexexamples.com/category/string/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>Finding out a characters Unicode character code</title>
		<link>http://blog.flexexamples.com/2007/07/21/finding-out-a-characters-unicode-character-code/</link>
		<comments>http://blog.flexexamples.com/2007/07/21/finding-out-a-characters-unicode-character-code/#comments</comments>
		<pubDate>Sun, 22 Jul 2007 06:25:32 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[Unicode]]></category>
		<category><![CDATA[charCodeAt()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/07/21/finding-out-a-characters-unicode-character-code-using-the-stringcharcodeat-method/</guid>
		<description><![CDATA[<p>Have you ever needed to know a character&#8217;s Unicode character code and had to spend minutes (or hours) looking it up? Well, here&#8217;s a little trick I learnt recently. ActionScript 3.0 (and ActionScript 2.0) have a handy little charCodeAt() method in the String class which takes a numeric parameter which specifies the desired character index in a string, [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever needed to know a character&#8217;s Unicode character code and had to spend minutes (or hours) looking it up? Well, here&#8217;s a little trick I learnt recently. ActionScript 3.0 (and ActionScript 2.0) have a handy little <code>charCodeAt()</code> method in the String class which takes a numeric parameter which specifies the desired character index in a string, and returns the numeric Unicode character code for that index. A poor explanation, I know, so lets take a look at some code</p>
<p><span id="more-15"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/String_charCodeAt_test/bin/srcview/String_charCodeAt_test.zip">Download source (ZIP, 1K)</a> | <a href="http://blog.flexexamples.com/wp-content/uploads/String_charCodeAt_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/07/21/finding-out-a-characters-unicode-character-code/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" backgroundColor="white" &gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            [Bindable]
            private var charCode:Number = "&amp;".charCodeAt();
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Label text="@ = {'@'.charCodeAt()}" /&gt;
    &lt;mx:Label text="&amp;amp; = {charCode}" /&gt;

&lt;/mx:Application&gt;</pre>
<p class="information">View source enabled in the following example.</p>
<p><iframe height="100" width="100%" src="http://blog.flexexamples.com/wp-content/uploads/String_charCodeAt_test/bin/main.html"></iframe></p>
<p>Not entirely interesting. Basically you define a string (in this case I just use an inline string rather than create a new temporary variable of String type) and then call the <code>charCodeAt()</code> method to convert that string into a number. The <code>charCodeAt()</code> method actually takes a single parameter, which, according to the documentation is:</p>
<blockquote><p>An integer that specifies the position of a character in the string. The first character is indicated by 0, and the last character is indicated by <code>my_str.length - 1</code>.</p></blockquote>
<p>If you don&#8217;t pass in any value, the index value defaults to zero, which is the first character in the string. Bingo!</p>
<p>Now that you&#8217;re all suitably underwhelmed, lets look at another example&#8230;</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/String_charCodeAt_test_2/bin/srcview/String_charCodeAt_test_2.zip">Download source (ZIP, 1K)</a> | <a href="http://blog.flexexamples.com/wp-content/uploads/String_charCodeAt_test_2/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/07/21/finding-out-a-characters-unicode-character-code/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.collections.ArrayCollection;

            [Bindable]
            private var arrColl:ArrayCollection;

            private function doChange():void {
                var letterArray:Array = textInput.text.split("");
                arrColl = new ArrayCollection(letterArray);
                dg.validateNow();
                dg.selectedIndex = arrColl.length;
                dg.scrollToIndex(arrColl.length);
            }

            private function CharCode(item:Object, column:DataGridColumn):String {
                return item.charCodeAt().toString();
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:TextInput id="textInput" change="doChange();" width="100%" /&gt;
    &lt;mx:DataGrid id="dg" dataProvider="{arrColl}" width="100%" height="100%"&gt;
        &lt;mx:columns&gt;
            &lt;mx:DataGridColumn headerText="Character" dataField="letter" /&gt;
            &lt;mx:DataGridColumn headerText="Char Code" labelFunction="CharCode" /&gt;
        &lt;/mx:columns&gt;
    &lt;/mx:DataGrid&gt;
    &lt;mx:Label id="lbl" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information">View source enabled in the following example.</p>
<p><iframe height="300" width="100%" src="http://blog.flexexamples.com/wp-content/uploads/String_charCodeAt_test_2/bin/main.html"></iframe></p>
<p>This example is marginally more interesting. Now you can type a string into the TextInput control and the character code for each letter will appear in the DataGrid control.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Finding out a characters Unicode character code on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/07/21/finding-out-a-characters-unicode-character-code/',contentID: 'post-15',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'charCodeAt()',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/07/21/finding-out-a-characters-unicode-character-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

