Share on Google+Share on Google+

String length property example

Advertisement
If user want to find out number of characters in a string. In this case String has a length property that return the number of characters in the specified String object.

String Length property example in Action Script3:-

If user want to find out number of characters in a string. In this case String has a length property that return the number of characters in the specified String object. In case of string null and empty, the string length is 0.

Example:-

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="init();">

<fx:Script>

<![CDATA[

private function init():void{

var str:String = "Brijesh says \'Hello Sir\'";

var strlength:Number = str.length;

myText1.text = str;

myText2.text = "The String length is " + strlength.toString();

}

]]>

</fx:Script>

<s:Panel width="200" height="200" title="String Length Panel" backgroundColor="0x81B5AA">

<s:VGroup>

<mx:Text id="myText1"/>

<mx:Text id="myText2"/>

</s:VGroup>

</s:Panel>

</s:Application>

In this example we have created a string type variable and initialize string value. After that we have apply length property to find out the length of the string.

Output:-

Download this code

Advertisements

Posted on: June 3, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.